on master help sign in
Haskell Language Server.novaextension/Scripts/download.js+14−24
since splitsnapshots
unifiedsplit
@@ -5,6 +5,8 @@ const {
5const {
5const {
6 readStream,
6 readStream,
7 getStorage,
7 getStorage,
8+ call,
9+ hasCustomEnv
8} = require("utils");
10} = require("utils");
9
11
10exports.getHLS = getHLS;
12exports.getHLS = getHLS;
@@ -43,6 +45,9 @@ async function downloadTool(name) {
43 const storagePath = getStorageForTool(name);
45 const storagePath = getStorageForTool(name);
44 console.log("Downloading " + storagePath);
46 console.log("Downloading " + storagePath);
45 const urls = await getHLSAssets();
47 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+ }
46 const response = await fetch(urls[name]);
51 const response = await fetch(urls[name]);
47 if (!response.ok) {
52 if (!response.ok) {
48 console.error(response.statusText);
53 console.error(response.statusText);
@@ -147,8 +152,12 @@ async function getHLS() {
147 return explicitPath
152 return explicitPath
148 }
153 }
149
154
150− const version = await getGHCVersion();
151 const localHLSPath = await which("haskell-language-server").catch((_) => null)
155 const localHLSPath = await which("haskell-language-server").catch((_) => null)
156+ if (hasCustomEnv() && localHLSPath) {
157+ return localHLSPath
158+ }
159+
160+ const version = await getGHCVersion();
152 if (localHLSPath) {
161 if (localHLSPath) {
153 sendNotification("Found HLS", "Found haskell-language-server in PATH. Checking if it is the right version.")
162 sendNotification("Found HLS", "Found haskell-language-server in PATH. Checking if it is the right version.")
154 const v = await getHLSVersion(localHLSPath)
163 const v = await getHLSVersion(localHLSPath)
@@ -175,35 +184,16 @@ function notifyToolDownloading(name) {
175}
184}
176
185
177function getHLSVersion(path) {
186function getHLSVersion(path) {
178− return call(new Process(path, {
187+ return call(path, {
179 args: ["--version"],
188 args: ["--version"],
180− }))
189+ })
181 .then((x) => x.match(/\(GHC: (\S+)\)/)[1].trim())
190 .then((x) => x.match(/\(GHC: (\S+)\)/)[1].trim())
182 .catch((err) => sendPermanentNotification("HLS version check failed", err))
191 .catch((err) => sendPermanentNotification("HLS version check failed", err))
183}
192}
184
193
185function which(name) {
194function which(name) {
186− return call(new Process("/usr/bin/which", {
195+ return call("/usr/bin/which", {
187 args: [name],
196 args: [name],
188 shell: true,
197 shell: true,
189− })).then((p) => p.trim())
198+ }).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
209}
199}
Haskell Language Server.novaextension/Scripts/main.js+5−6
@@ -9,8 +9,9 @@ const {
9 getHLSConfig,
9 getHLSConfig,
10} = require("configuration");
10} = require("configuration");
11const {
11const {
12− getFileName,
12+ getFileName, createEnv, getEnv
13} = require("utils");
13} = require("utils");
14+
14exports.activate = function () {
15exports.activate = function () {
15 nova.commands.register("stop", (_workspace) => {
16 nova.commands.register("stop", (_workspace) => {
16 stopServer();
17 stopServer();
@@ -107,10 +108,12 @@ function applyAllLSPEdits(edits, text) {
107}
108}
108let lspClient = null;
109let lspClient = null;
109async function startServer() {
110async function startServer() {
111+ await createEnv()
110 stopServer();
112 stopServer();
111 const path = await getServerPath();
113 const path = await getServerPath();
114+ const env = await getEnv()
112 const serverOptions = {
115 const serverOptions = {
113− path: path,
116+ path, env,
114 args: ["lsp", "--cwd", nova.workspace.path],
117 args: ["lsp", "--cwd", nova.workspace.path],
115 };
118 };
116 const clientOptions = {
119 const clientOptions = {
@@ -137,7 +140,3 @@ function stopServer() {
137function getServerPath() {
140function getServerPath() {
138 return getHLS();
141 return getHLS();
139}
142}
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+
1function readStream(readableStream) {
6function readStream(readableStream) {
2 return new Promise((resolve, _reject) => {
7 return new Promise((resolve, _reject) => {
3 const reader = readableStream.getReader();
8 const reader = readableStream.getReader();
@@ -48,4 +53,90 @@ function traceRaw(x) {
48 return x;
53 return x;
49}
54}
50
55
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+
51−module.exports = { readStream, getStorage, getFileName, trace, traceRaw };
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 @@
65
65
66 <template-scopes>
66 <template-scopes>
67 <include syntax="self" collection="Quote" />
67 <include syntax="self" collection="Quote" />
68− <include syntax="self" collection="comments" />
69 </template-scopes>
68 </template-scopes>
70
69
71 <collections>
70 <collections>
@@ -137,6 +136,7 @@
137 <capture number="1" name="haskell.pattern.record.bracket" />
136 <capture number="1" name="haskell.pattern.record.bracket" />
138 </ends-with>
137 </ends-with>
139 <subscopes>
138 <subscopes>
139+ <include syntax="self" collection="comments" />
140 <include syntax="self" collection="expressions" />
140 <include syntax="self" collection="expressions" />
141 <scope name="record-sep">
141 <scope name="record-sep">
142 <expression>=</expression>
142 <expression>=</expression>
@@ -159,6 +159,7 @@
159 <capture number="1" name="haskell.pattern.record.bracket" />
159 <capture number="1" name="haskell.pattern.record.bracket" />
160 </ends-with>
160 </ends-with>
161 <subscopes>
161 <subscopes>
162+ <include syntax="self" collection="comments" />
162 <scope name="haskell.pattern.record.wildcard">
163 <scope name="haskell.pattern.record.wildcard">
163 <expression>\.\.</expression>
164 <expression>\.\.</expression>
164 </scope>
165 </scope>
@@ -185,6 +186,7 @@
185 <capture number="1" name="haskell.list.bracket" />
186 <capture number="1" name="haskell.list.bracket" />
186 </ends-with>
187 </ends-with>
187 <subscopes>
188 <subscopes>
189+ <include syntax="self" collection="comments" />
188 <include syntax="self" collection="expressions" />
190 <include syntax="self" collection="expressions" />
189 </subscopes>
191 </subscopes>
190 </scope>
192 </scope>
@@ -239,6 +241,7 @@
239 <capture number="1" name="haskell.tuple.bracket" />
241 <capture number="1" name="haskell.tuple.bracket" />
240 </ends-with>
242 </ends-with>
241 <subscopes>
243 <subscopes>
244+ <include syntax="self" collection="comments" />
242 <include syntax="self" collection="expressions" />
245 <include syntax="self" collection="expressions" />
243 </subscopes>
246 </subscopes>
244 </scope>
247 </scope>
@@ -263,6 +266,7 @@
263 <expression>(?=(where|^\s*$))</expression>
266 <expression>(?=(where|^\s*$))</expression>
264 </ends-with>
267 </ends-with>
265 <subscopes>
268 <subscopes>
269+ <include syntax="self" collection="comments" />
266 <include syntax="self" collection="type" />
270 <include syntax="self" collection="type" />
267 </subscopes>
271 </subscopes>
268 </scope>
272 </scope>
@@ -342,6 +346,7 @@
342 <template>^(?!\s+\1\S)(?!\s*$)</template>
346 <template>^(?!\s+\1\S)(?!\s*$)</template>
343 </ends-with>
347 </ends-with>
344 <subscopes>
348 <subscopes>
349+ <include syntax="self" collection="comments" />
345 <include syntax="self" collection="type" optional="true" repeat="true" />
350 <include syntax="self" collection="type" optional="true" repeat="true" />
346 <scope>
351 <scope>
347 <expression>=</expression>
352 <expression>=</expression>
@@ -365,6 +370,7 @@
365 <template>^(?!\1\3\s)(?!\s+\1\S)(?!\s*$)</template>
370 <template>^(?!\1\3\s)(?!\s+\1\S)(?!\s*$)</template>
366 </ends-with>
371 </ends-with>
367 <subscopes>
372 <subscopes>
373+ <include syntax="self" collection="comments" />
368 <include syntax="self" collection="type-annotation" />
374 <include syntax="self" collection="type-annotation" />
369 <include syntax="self" collection="implementation" />
375 <include syntax="self" collection="implementation" />
370 </subscopes>
376 </subscopes>
@@ -382,6 +388,7 @@
382 <template>^(?!\1\3\s)(?!\s+\1\S)(?!\s*$)</template>
388 <template>^(?!\1\3\s)(?!\s+\1\S)(?!\s*$)</template>
383 </ends-with>
389 </ends-with>
384 <subscopes>
390 <subscopes>
391+ <include syntax="self" collection="comments" />
385 <include syntax="self" collection="pattern-match" optional="true" repeat="true" />
392 <include syntax="self" collection="pattern-match" optional="true" repeat="true" />
386 <scope>
393 <scope>
387 <expression>=</expression>
394 <expression>=</expression>
@@ -403,6 +410,7 @@
403 <template>^(?!\s+\1\S)(?!\s*$)</template>
410 <template>^(?!\s+\1\S)(?!\s*$)</template>
404 </ends-with>
411 </ends-with>
405 <subscopes>
412 <subscopes>
413+ <include syntax="self" collection="comments" />
406 <include syntax="self" collection="type" />
414 <include syntax="self" collection="type" />
407 </subscopes>
415 </subscopes>
408 </scope>
416 </scope>
@@ -422,6 +430,7 @@
422 <template>^(?!\s+\1\S)(?!\s*$)</template>
430 <template>^(?!\s+\1\S)(?!\s*$)</template>
423 </ends-with>
431 </ends-with>
424 <subscopes>
432 <subscopes>
433+ <include syntax="self" collection="comments" />
425 <include syntax="self" collection="type" />
434 <include syntax="self" collection="type" />
426 </subscopes>
435 </subscopes>
427 </scope>
436 </scope>
@@ -441,6 +450,7 @@
441 <template>^(?!\s+\1\S)(?!\s*$)</template>
450 <template>^(?!\s+\1\S)(?!\s*$)</template>
442 </ends-with>
451 </ends-with>
443 <subscopes>
452 <subscopes>
453+ <include syntax="self" collection="comments" />
444 <scope name="haskell.keyword.construct.where">
454 <scope name="haskell.keyword.construct.where">
445 <expression>where</expression>
455 <expression>where</expression>
446 </scope>
456 </scope>
@@ -474,6 +484,7 @@
474 <expression>deriving(\h+(newtype|stock|anyclass))?</expression>
484 <expression>deriving(\h+(newtype|stock|anyclass))?</expression>
475 </scope>
485 </scope>
476 <scope name="haskell.record.construct.deriving.keyword">
486 <scope name="haskell.record.construct.deriving.keyword">
487+ <include syntax="self" collection="comments" />
477 <expression>via</expression>
488 <expression>via</expression>
478 </scope>
489 </scope>
479 </collection>
490 </collection>
@@ -492,6 +503,7 @@
492 <capture number="1" name="haskell.record.bracket" />
503 <capture number="1" name="haskell.record.bracket" />
493 </ends-with>
504 </ends-with>
494 <subscopes>
505 <subscopes>
506+ <include syntax="self" collection="comments" />
495 <include syntax="self" collection="record-definition-field-name" />
507 <include syntax="self" collection="record-definition-field-name" />
496 <include syntax="self" collection="type" />
508 <include syntax="self" collection="type" />
497 </subscopes>
509 </subscopes>
@@ -523,6 +535,7 @@
523 <expression>\)</expression>
535 <expression>\)</expression>
524 </ends-with>
536 </ends-with>
525 <subscopes>
537 <subscopes>
538+ <include syntax="self" collection="comments" />
526 <scope name="haskell.construct.type.typle.comma">
539 <scope name="haskell.construct.type.typle.comma">
527 <expression>\,</expression>
540 <expression>\,</expression>
528 </scope>
541 </scope>
@@ -537,6 +550,7 @@
537 <expression>\]</expression>
550 <expression>\]</expression>
538 </ends-with>
551 </ends-with>
539 <subscopes>
552 <subscopes>
553+ <include syntax="self" collection="comments" />
540 <include syntax="self" collection="type" />
554 <include syntax="self" collection="type" />
541 </subscopes>
555 </subscopes>
542 </scope>
556 </scope>
@@ -571,6 +585,7 @@
571 <template>^(?!\s+\1\S)(?!\s*$)</template>
585 <template>^(?!\s+\1\S)(?!\s*$)</template>
572 </ends-with>
586 </ends-with>
573 <subscopes>
587 <subscopes>
588+ <include syntax="self" collection="comments" />
574 <scope name="haskell.keyword.construct.where">
589 <scope name="haskell.keyword.construct.where">
575 <expression>where</expression>
590 <expression>where</expression>
576 </scope>
591 </scope>
@@ -590,6 +605,7 @@
590 <capture number="1" name="haskell.type-list.bracket" />
605 <capture number="1" name="haskell.type-list.bracket" />
591 </ends-with>
606 </ends-with>
592 <subscopes>
607 <subscopes>
608+ <include syntax="self" collection="comments" />
593 <include syntax="self" collection="type" />
609 <include syntax="self" collection="type" />
594 </subscopes>
610 </subscopes>
595 </scope>
611 </scope>
@@ -606,6 +622,7 @@
606 <capture number="1" name="haskell.keyword.construct.lambda" />
622 <capture number="1" name="haskell.keyword.construct.lambda" />
607 </ends-with>
623 </ends-with>
608 <subscopes>
624 <subscopes>
625+ <include syntax="self" collection="comments" />
609 <include syntax="self" collection="pattern-match" />
626 <include syntax="self" collection="pattern-match" />
610 </subscopes>
627 </subscopes>
611 </scope>
628 </scope>
@@ -627,6 +644,7 @@
627 <template>^(?!\1\s*\S)(?!s*$)</template>
644 <template>^(?!\1\s*\S)(?!s*$)</template>
628 </ends-with>
645 </ends-with>
629 <subscopes>
646 <subscopes>
647+ <include syntax="self" collection="comments" />
630 <include syntax="self" collection="definition" />
648 <include syntax="self" collection="definition" />
631 </subscopes>
649 </subscopes>
632 </scope>
650 </scope>
@@ -666,12 +684,12 @@
666
684
667
685
668 <collection name="strings">
686 <collection name="strings">
669− <scope name="haskell.string.double-quoted">
687+ <scope name="haskell.string.double-quoted" spell-check="true">
670 <starts-with>
688 <starts-with>
671− <expression>"</expression>
689+ <expression>&quot;</expression>
672 </starts-with>
690 </starts-with>
673 <ends-with>
691 <ends-with>
674− <expression>"</expression>
692+ <expression>&quot;</expression>
675 </ends-with>
693 </ends-with>
676 <subscopes>
694 <subscopes>
677 <scope name="haskell.string.escape-sequences">
695 <scope name="haskell.string.escape-sequences">
@@ -708,6 +726,7 @@
708 </ends-with>
726 </ends-with>
709 <subscopes>
727 <subscopes>
710 <scope name="identifier.haskell.type">
728 <scope name="identifier.haskell.type">
729+ <symbol type="expression" />
711 <symbol type="expression" />
730 <symbol type="expression" />
712 <expression>([A-Z](\w|')*)\h*(\(\h*\.\.\h*\))?</expression>
731 <expression>([A-Z](\w|')*)\h*(\(\h*\.\.\h*\))?</expression>
713 <capture number="1" name="identifier.type" />
732 <capture number="1" name="identifier.type" />
@@ -732,6 +751,7 @@
732 </ends-with>
751 </ends-with>
733 <subscopes>
752 <subscopes>
734 <scope name="haskell.construct.qualified">
753 <scope name="haskell.construct.qualified">
754+ <symbol type="expression" />
735 <expression>qualified</expression>
755 <expression>qualified</expression>
736 <capture number="0" name="haskell.construct.keyword.qualified" />
756 <capture number="0" name="haskell.construct.keyword.qualified" />
737 </scope>
757 </scope>
@@ -749,6 +769,7 @@
749 </ends-with>
769 </ends-with>
750 <subscopes anchored="true">
770 <subscopes anchored="true">
751 <include syntax="self" collection="import-list" />
771 <include syntax="self" collection="import-list" />
772+ <symbol type="expression" />
752 </subscopes>
773 </subscopes>
753 </scope>
774 </scope>
754
775
@@ -782,6 +803,7 @@
782 </ends-with>
803 </ends-with>
783 <subscopes>
804 <subscopes>
784 <scope name="haskell.identifier.struct">
805 <scope name="haskell.identifier.struct">
806+ <symbol type="expression" />
785 <symbol type="reference" scope="local" />
807 <symbol type="reference" scope="local" />
786 <expression>([A-Z](\w|')*)\h*(\(\h*\.\.\h*\))?</expression>
808 <expression>([A-Z](\w|')*)\h*(\(\h*\.\.\h*\))?</expression>
787 <capture number="1" name="haskell.import-list.identifier.type.name" />
809 <capture number="1" name="haskell.import-list.identifier.type.name" />
@@ -851,14 +873,11 @@
851
873
852 <collection name="comments">
874 <collection name="comments">
853 <scope name="haskell.comment.single" spell-check="true">
875 <scope name="haskell.comment.single" spell-check="true">
854− <starts-with>
876+ <symbol type="comment" />
855− <expression>--</expression>
856− </starts-with>
857− <ends-with>
858− <expression>$</expression>
877+ <expression> --.*$</expression>
859− </ends-with>
860 </scope>
878 </scope>
861 <scope name="haskell.comment.block" spell-check="true">
879 <scope name="haskell.comment.block" spell-check="true">
880+ <symbol type="comment" />
862 <starts-with>
881 <starts-with>
863 <expression>{-</expression>
882 <expression>{-</expression>
864 </starts-with>
883 </starts-with>
Haskell Language Server.novaextension/extension.json+8
@@ -20,6 +20,14 @@
20 "type": "path",
20 "type": "path",
21 "placeholder": "/usr/local/bin/example"
21 "placeholder": "/usr/local/bin/example"
22 },
22 },
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+ },
23 {
31 {
24 "type": "section",
32 "type": "section",
25 "title": "Haskell Language Server settings",
33 "title": "Haskell Language Server settings",