on master help sign in
5 files changed+148−41
since splitsnapshots
unifiedsplit
Haskell Language Server.novaextension/Scripts/download.js+14−24 Haskell Language Server.novaextension/Scripts/main.js+5−6 Haskell Language Server.novaextension/Scripts/utils.js+92−1 Haskell Language Server.novaextension/Syntaxes/Haskell.xml+29−10 Haskell Language Server.novaextension/extension.json+8
Haskell Language Server.novaextension/Scripts/download.js+14−24
@@ -5,6 +5,8 @@ const {
55const {
66 readStream,
77 getStorage,
8+ call,
9+ hasCustomEnv
810} = require("utils");
911
1012exports.getHLS = getHLS;
@@ -43,6 +45,9 @@ async function downloadTool(name) {
4345 const storagePath = getStorageForTool(name);
4446 console.log("Downloading " + storagePath);
4547 const urls = await getHLSAssets();
48+ if (!(name in urls)) {
49+ sendPermanentNotification("There is no pre-built HLS for GHC " + name ,"There is no pre-built version of HLS for GHC " + name + ". You can either build HLS yourself or update your project to one of the pre-built versions: https://github.com/haskell/haskell-language-server/releases")
50+ }
4651 const response = await fetch(urls[name]);
4752 if (!response.ok) {
4853 console.error(response.statusText);
@@ -147,8 +152,12 @@ async function getHLS() {
147152 return explicitPath
148153 }
149154
150− const version = await getGHCVersion();
151155 const localHLSPath = await which("haskell-language-server").catch((_) => null)
156+ if (hasCustomEnv() && localHLSPath) {
157+ return localHLSPath
158+ }
159+
160+ const version = await getGHCVersion();
152161 if (localHLSPath) {
153162 sendNotification("Found HLS", "Found haskell-language-server in PATH. Checking if it is the right version.")
154163 const v = await getHLSVersion(localHLSPath)
@@ -175,35 +184,16 @@ function notifyToolDownloading(name) {
175184}
176185
177186function getHLSVersion(path) {
178− return call(new Process(path, {
187+ return call(path, {
179188 args: ["--version"],
180− }))
189+ })
181190 .then((x) => x.match(/\(GHC: (\S+)\)/)[1].trim())
182191 .catch((err) => sendPermanentNotification("HLS version check failed", err))
183192}
184193
185194function which(name) {
186− return call(new Process("/usr/bin/which", {
195+ return call("/usr/bin/which", {
187196 args: [name],
188197 shell: true,
189− })).then((p) => p.trim())
190−}
191−
192−function call(process) {
193− const promise = new Promise((resolve, reject) => {
194− process.onDidExit((exitCode) => {
195− console.log(exitCode)
196− if (exitCode == 0) {
197− readStream(process.stdout).then((x) => {
198− resolve(x);
199− });
200− } else {
201− readStream(process.stderr).then((x) => {
202− reject(x)
203− });
204− }
205− });
206− })
207− process.start()
208− return promise
198+ }).then((p) => p.trim())
209199}
Haskell Language Server.novaextension/Scripts/main.js+5−6
@@ -9,8 +9,9 @@ const {
99 getHLSConfig,
1010} = require("configuration");
1111const {
12− getFileName,
12+ getFileName, createEnv, getEnv
1313} = require("utils");
14+
1415exports.activate = function () {
1516 nova.commands.register("stop", (_workspace) => {
1617 stopServer();
@@ -107,10 +108,12 @@ function applyAllLSPEdits(edits, text) {
107108}
108109let lspClient = null;
109110async function startServer() {
111+ await createEnv()
110112 stopServer();
111113 const path = await getServerPath();
114+ const env = await getEnv()
112115 const serverOptions = {
113− path: path,
116+ path, env,
114117 args: ["lsp", "--cwd", nova.workspace.path],
115118 };
116119 const clientOptions = {
@@ -137,7 +140,3 @@ function stopServer() {
137140function getServerPath() {
138141 return getHLS();
139142}
140−
141−// function getLogPath() {
142−// return getStorage() + "/haskell-language-server.log";
143−// }
Haskell Language Server.novaextension/Scripts/utils.js+92−1
@@ -1,3 +1,8 @@
1+const {
2+ sendNotification,
3+ sendPermanentNotification,
4+} = require("notifications");
5+
16function readStream(readableStream) {
27 return new Promise((resolve, _reject) => {
38 const reader = readableStream.getReader();
@@ -48,4 +53,90 @@ function traceRaw(x) {
4853 return x;
4954}
5055
51−module.exports = { readStream, getStorage, getFileName, trace, traceRaw };
56+async function call(path, args) {
57+ const env = await getEnv()
58+ const process = new Process(path, {...args, ...{env}});
59+ const promise = new Promise((resolve, reject) => {
60+ process.onDidExit((exitCode) => {
61+ console.log(exitCode)
62+ if (exitCode == 0) {
63+ readStream(process.stdout).then((x) => {
64+ resolve(x);
65+ });
66+ } else {
67+ readStream(process.stderr).then((x) => {
68+ reject(x)
69+ });
70+ }
71+ });
72+ })
73+ process.start()
74+ return promise
75+}
76+
77+
78+function parseEnvs(x) {
79+ const env = {}
80+ for (line of x.split("\n")) {
81+ const res = line.match(/(.*?)=(.*)/)
82+ if (res) {
83+ env[res[1]] = res[2]
84+ }
85+ }
86+
87+ console.log(JSON.stringify(env))
88+
89+ return env
90+}
91+
92+let envCache = null
93+
94+async function createEnv() {
95+ const generator = nova.workspace.config.get("env-generator")
96+ if (generator) {
97+ const [prog, ...args] = generator.split(/\s+/)
98+ sendNotification("Generating environment", "Executing " + generator + ".")
99+ const process = new Process(prog, {
100+ shell: true,
101+ args,
102+ cwd: nova.workspace.path
103+ });
104+ const promise = new Promise((resolve, reject) => {
105+ process.onDidExit((exitCode) => {
106+ console.log(exitCode)
107+ if (exitCode == 0) {
108+ readStream(process.stdout).then((x) => {
109+ resolve(x);
110+ });
111+ } else {
112+ readStream(process.stderr).then((x) => {
113+ reject(x)
114+ });
115+ }
116+ });
117+ })
118+ process.start()
119+
120+ const envStr = await promise
121+ .catch((err) => sendPermanentNotification("Generating environment failed", err))
122+ envCache = parseEnvs(envStr)
123+ } else {
124+ envCache = {}
125+ }
126+}
127+
128+async function getEnv() {
129+ console.log(JSON.stringify(envCache))
130+ if (!envCache) {
131+ await createEnv()
132+ }
133+ return envCache
134+}
135+
136+
137+function hasCustomEnv() {
138+ return (nova.workspace.config.get("env-generator") !== null)
139+}
140+
141+module.exports = { readStream, getStorage, getFileName, trace, traceRaw, call, createEnv, hasCustomEnv, getEnv };
142+
Haskell Language Server.novaextension/Syntaxes/Haskell.xml+29−10
@@ -65,7 +65,6 @@
6565
6666 <template-scopes>
6767 <include syntax="self" collection="Quote" />
68− <include syntax="self" collection="comments" />
6968 </template-scopes>
7069
7170 <collections>
@@ -137,6 +136,7 @@
137136 <capture number="1" name="haskell.pattern.record.bracket" />
138137 </ends-with>
139138 <subscopes>
139+ <include syntax="self" collection="comments" />
140140 <include syntax="self" collection="expressions" />
141141 <scope name="record-sep">
142142 <expression>=</expression>
@@ -159,6 +159,7 @@
159159 <capture number="1" name="haskell.pattern.record.bracket" />
160160 </ends-with>
161161 <subscopes>
162+ <include syntax="self" collection="comments" />
162163 <scope name="haskell.pattern.record.wildcard">
163164 <expression>\.\.</expression>
164165 </scope>
@@ -185,6 +186,7 @@
185186 <capture number="1" name="haskell.list.bracket" />
186187 </ends-with>
187188 <subscopes>
189+ <include syntax="self" collection="comments" />
188190 <include syntax="self" collection="expressions" />
189191 </subscopes>
190192 </scope>
@@ -239,6 +241,7 @@
239241 <capture number="1" name="haskell.tuple.bracket" />
240242 </ends-with>
241243 <subscopes>
244+ <include syntax="self" collection="comments" />
242245 <include syntax="self" collection="expressions" />
243246 </subscopes>
244247 </scope>
@@ -263,6 +266,7 @@
263266 <expression>(?=(where|^\s*$))</expression>
264267 </ends-with>
265268 <subscopes>
269+ <include syntax="self" collection="comments" />
266270 <include syntax="self" collection="type" />
267271 </subscopes>
268272 </scope>
@@ -342,6 +346,7 @@
342346 <template>^(?!\s+\1\S)(?!\s*$)</template>
343347 </ends-with>
344348 <subscopes>
349+ <include syntax="self" collection="comments" />
345350 <include syntax="self" collection="type" optional="true" repeat="true" />
346351 <scope>
347352 <expression>=</expression>
@@ -365,6 +370,7 @@
365370 <template>^(?!\1\3\s)(?!\s+\1\S)(?!\s*$)</template>
366371 </ends-with>
367372 <subscopes>
373+ <include syntax="self" collection="comments" />
368374 <include syntax="self" collection="type-annotation" />
369375 <include syntax="self" collection="implementation" />
370376 </subscopes>
@@ -382,6 +388,7 @@
382388 <template>^(?!\1\3\s)(?!\s+\1\S)(?!\s*$)</template>
383389 </ends-with>
384390 <subscopes>
391+ <include syntax="self" collection="comments" />
385392 <include syntax="self" collection="pattern-match" optional="true" repeat="true" />
386393 <scope>
387394 <expression>=</expression>
@@ -403,6 +410,7 @@
403410 <template>^(?!\s+\1\S)(?!\s*$)</template>
404411 </ends-with>
405412 <subscopes>
413+ <include syntax="self" collection="comments" />
406414 <include syntax="self" collection="type" />
407415 </subscopes>
408416 </scope>
@@ -422,6 +430,7 @@
422430 <template>^(?!\s+\1\S)(?!\s*$)</template>
423431 </ends-with>
424432 <subscopes>
433+ <include syntax="self" collection="comments" />
425434 <include syntax="self" collection="type" />
426435 </subscopes>
427436 </scope>
@@ -441,6 +450,7 @@
441450 <template>^(?!\s+\1\S)(?!\s*$)</template>
442451 </ends-with>
443452 <subscopes>
453+ <include syntax="self" collection="comments" />
444454 <scope name="haskell.keyword.construct.where">
445455 <expression>where</expression>
446456 </scope>
@@ -474,6 +484,7 @@
474484 <expression>deriving(\h+(newtype|stock|anyclass))?</expression>
475485 </scope>
476486 <scope name="haskell.record.construct.deriving.keyword">
487+ <include syntax="self" collection="comments" />
477488 <expression>via</expression>
478489 </scope>
479490 </collection>
@@ -492,6 +503,7 @@
492503 <capture number="1" name="haskell.record.bracket" />
493504 </ends-with>
494505 <subscopes>
506+ <include syntax="self" collection="comments" />
495507 <include syntax="self" collection="record-definition-field-name" />
496508 <include syntax="self" collection="type" />
497509 </subscopes>
@@ -523,6 +535,7 @@
523535 <expression>\)</expression>
524536 </ends-with>
525537 <subscopes>
538+ <include syntax="self" collection="comments" />
526539 <scope name="haskell.construct.type.typle.comma">
527540 <expression>\,</expression>
528541 </scope>
@@ -537,6 +550,7 @@
537550 <expression>\]</expression>
538551 </ends-with>
539552 <subscopes>
553+ <include syntax="self" collection="comments" />
540554 <include syntax="self" collection="type" />
541555 </subscopes>
542556 </scope>
@@ -571,6 +585,7 @@
571585 <template>^(?!\s+\1\S)(?!\s*$)</template>
572586 </ends-with>
573587 <subscopes>
588+ <include syntax="self" collection="comments" />
574589 <scope name="haskell.keyword.construct.where">
575590 <expression>where</expression>
576591 </scope>
@@ -590,6 +605,7 @@
590605 <capture number="1" name="haskell.type-list.bracket" />
591606 </ends-with>
592607 <subscopes>
608+ <include syntax="self" collection="comments" />
593609 <include syntax="self" collection="type" />
594610 </subscopes>
595611 </scope>
@@ -606,6 +622,7 @@
606622 <capture number="1" name="haskell.keyword.construct.lambda" />
607623 </ends-with>
608624 <subscopes>
625+ <include syntax="self" collection="comments" />
609626 <include syntax="self" collection="pattern-match" />
610627 </subscopes>
611628 </scope>
@@ -627,6 +644,7 @@
627644 <template>^(?!\1\s*\S)(?!s*$)</template>
628645 </ends-with>
629646 <subscopes>
647+ <include syntax="self" collection="comments" />
630648 <include syntax="self" collection="definition" />
631649 </subscopes>
632650 </scope>
@@ -666,12 +684,12 @@
666684
667685
668686 <collection name="strings">
669− <scope name="haskell.string.double-quoted">
687+ <scope name="haskell.string.double-quoted" spell-check="true">
670688 <starts-with>
671− <expression>"</expression>
689+ <expression>&quot;</expression>
672690 </starts-with>
673691 <ends-with>
674− <expression>"</expression>
692+ <expression>&quot;</expression>
675693 </ends-with>
676694 <subscopes>
677695 <scope name="haskell.string.escape-sequences">
@@ -708,6 +726,7 @@
708726 </ends-with>
709727 <subscopes>
710728 <scope name="identifier.haskell.type">
729+ <symbol type="expression" />
711730 <symbol type="expression" />
712731 <expression>([A-Z](\w|')*)\h*(\(\h*\.\.\h*\))?</expression>
713732 <capture number="1" name="identifier.type" />
@@ -732,6 +751,7 @@
732751 </ends-with>
733752 <subscopes>
734753 <scope name="haskell.construct.qualified">
754+ <symbol type="expression" />
735755 <expression>qualified</expression>
736756 <capture number="0" name="haskell.construct.keyword.qualified" />
737757 </scope>
@@ -749,6 +769,7 @@
749769 </ends-with>
750770 <subscopes anchored="true">
751771 <include syntax="self" collection="import-list" />
772+ <symbol type="expression" />
752773 </subscopes>
753774 </scope>
754775
@@ -782,6 +803,7 @@
782803 </ends-with>
783804 <subscopes>
784805 <scope name="haskell.identifier.struct">
806+ <symbol type="expression" />
785807 <symbol type="reference" scope="local" />
786808 <expression>([A-Z](\w|')*)\h*(\(\h*\.\.\h*\))?</expression>
787809 <capture number="1" name="haskell.import-list.identifier.type.name" />
@@ -851,14 +873,11 @@
851873
852874 <collection name="comments">
853875 <scope name="haskell.comment.single" spell-check="true">
854− <starts-with>
855− <expression>--</expression>
856− </starts-with>
857− <ends-with>
858− <expression>$</expression>
859− </ends-with>
876+ <symbol type="comment" />
877+ <expression> --.*$</expression>
860878 </scope>
861879 <scope name="haskell.comment.block" spell-check="true">
880+ <symbol type="comment" />
862881 <starts-with>
863882 <expression>{-</expression>
864883 </starts-with>
Haskell Language Server.novaextension/extension.json+8
@@ -20,6 +20,14 @@
2020 "type": "path",
2121 "placeholder": "/usr/local/bin/example"
2222 },
23+ {
24+ "key": "env-generator",
25+ "title": "Environment generator",
26+ "description": "You can specify a shell command which will be used to generate the environment, in which the extension will be executes. This is useful if you want to utilize `nix-shell`, `direnv` or any similar command.\n\nExpects the command to have the same stdout as the `env` command.",
27+ "type": "enum",
28+ "allowsCustom": true,
29+ "values": ["nix-shell --run env", "direnv exec env"]
30+ },
2331 {
2432 "type": "section",
2533 "title": "Haskell Language Server settings",