Skip to content

Commit e90e590

Browse files
committed
Use the platform binary
Faster
1 parent eb2d70e commit e90e590

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,5 @@ Tldr (documented in first link):
4545
- Change `ReScript.sublime-syntax`
4646
- Open `syntax_test.res`
4747
- Command Palette -> Build With: Syntax Tests
48+
49+
For more grammar inspirations, check ST's own [JavaScript grammar](https://github.com/sublimehq/Packages/blob/2c66f1fdea0dbc74aaa3b1c2f904040e9c1aaefa/JavaScript/JavaScript.sublime-syntax).

format.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,26 @@
55
import os
66
import tempfile
77
import pathlib
8+
import platform
89

910
SETTINGS_PATH = 'Default.sublime-settings'
1011

1112
resExt = ".res"
1213
resiExt = ".resi"
14+
platformSystem = platform.system()
15+
# rescript currently supports 3 platforms: darwin, linux, win32. these also
16+
# happen to be folder names for the location of the bsc binary. We're in
17+
# python, so we're gonna translate python's output of system to nodejs'
18+
# Why don't we just use the binary in node_modules/.bin/bsc? Because that
19+
# one's a nodejs wrapper, which has a startup cost. It makes it so that every
20+
# time we call it for e.g. formatting, the result janks a little.
21+
platformInNodeJS = "linux"
22+
if platformSystem == "Darwin":
23+
platformInNodeJS = "darwin"
24+
elif platformSystem == "Windows":
25+
platformInNodeJS = "win32"
26+
27+
bscPartialPath = os.path.join("node_modules", "bs-platform", platformInNodeJS, "bsc.exe")
1328

1429
def findBsConfigDirFromFilename(filename):
1530
currentDir = os.path.dirname(filename)
@@ -143,8 +158,7 @@ def findFormatter(view, filename):
143158
)
144159
return None
145160
else:
146-
# TODO: find the right platform binary
147-
bscExe = os.path.join(bsconfigDir, "node_modules", ".bin", "bsc")
161+
bscExe = os.path.join(bsconfigDir, bscPartialPath)
148162
if os.path.exists(bscExe):
149163
return bscExe
150164
else:
@@ -194,7 +208,7 @@ def run(self, edit, formatBuffer=True):
194208
view.text_point(range_["end"]["line"], range_["end"]["character"]),
195209
)
196210
regions.append(region)
197-
html = '<body id="my-plugin-feature"> <style> div.error {padding: 5px; } </style> <div class="error">' + message + '</div> </body>'
211+
html = '<body> <style> div.error {padding: 5px; border-radius: 8px;} </style> <div class="error">' + message + '</div> </body>'
198212
view.add_phantom("errns", region, html, sublime.LAYOUT_BELOW)
199213

200214
view.add_regions('syntaxerror', regions, 'invalid.illegal', 'dot', sublime.DRAW_NO_FILL)

0 commit comments

Comments
 (0)