on 3eb1500 help sign in
5 files changed+41−148
since splitsnapshots
unifiedsplit
Haskell Language Server.novaextension/Scripts/download.js+24−14 Haskell Language Server.novaextension/Scripts/main.js+6−5 Haskell Language Server.novaextension/Scripts/utils.js+1−92 Haskell Language Server.novaextension/Syntaxes/Haskell.xml+10−29 Haskell Language Server.novaextension/extension.json−8
Haskell Language Server.novaextension/Scripts/download.js+24−14
@@ -5,8 +5,6 @@ const {
55const {
66 readStream,
77 getStorage,
8− call,
9− hasCustomEnv
108} = require("utils");
119
1210exports.getHLS = getHLS;
@@ -45,9 +43,6 @@ async function downloadTool(name) {
4543 const storagePath = getStorageForTool(name);
4644 console.log("Downloading " + storagePath);
4745 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− }
5146 const response = await fetch(urls[name]);
5247 if (!response.ok) {
5348 console.error(response.statusText);
@@ -152,12 +147,8 @@ async function getHLS() {
152147 return explicitPath
153148 }
154149
155− const localHLSPath = await which("haskell-language-server").catch((_) => null)
156− if (hasCustomEnv() && localHLSPath) {
157− return localHLSPath
158− }
159−
160150 const version = await getGHCVersion();
151+ const localHLSPath = await which("haskell-language-server").catch((_) => null)
161152 if (localHLSPath) {
162153 sendNotification("Found HLS", "Found haskell-language-server in PATH. Checking if it is the right version.")
163154 const v = await getHLSVersion(localHLSPath)
@@ -184,16 +175,35 @@ function notifyToolDownloading(name) {
184175}
185176
186177function getHLSVersion(path) {
187− return call(path, {
178+ return call(new Process(path, {
188179 args: ["--version"],
189− })
180+ }))
190181 .then((x) => x.match(/\(GHC: (\S+)\)/)[1].trim())
191182 .catch((err) => sendPermanentNotification("HLS version check failed", err))
192183}
193184
194185function which(name) {
195− return call("/usr/bin/which", {
186+ return call(new Process("/usr/bin/which", {
196187 args: [name],
197188 shell: true,
198− }).then((p) => p.trim())
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
199209}
Haskell Language Server.novaextension/Scripts/main.js+6−5
@@ -9,9 +9,8 @@ const {
99 getHLSConfig,
1010} = require("configuration");
1111const {
12− getFileName, createEnv, getEnv
12+ getFileName,
1313} = require("utils");
14−
1514exports.activate = function () {
1615 nova.commands.register("stop", (_workspace) => {
1716 stopServer();
@@ -108,12 +107,10 @@ function applyAllLSPEdits(edits, text) {
108107}
109108let lspClient = null;
110109async function startServer() {
111− await createEnv()
112110 stopServer();
113111 const path = await getServerPath();
114− const env = await getEnv()
115112 const serverOptions = {
116− path, env,
113+ path: path,
117114 args: ["lsp", "--cwd", nova.workspace.path],
118115 };
119116 const clientOptions = {
@@ -140,3 +137,7 @@ function stopServer() {
140137function getServerPath() {
141138 return getHLS();
142139}
140+
141+// function getLogPath() {
142+// return getStorage() + "/haskell-language-server.log";
143+// }
Haskell Language Server.novaextension/Scripts/utils.js+1−92
@@ -1,8 +1,3 @@
1−const {
2− sendNotification,
3− sendPermanentNotification,
4−} = require("notifications");
5−
61function readStream(readableStream) {
72 return new Promise((resolve, _reject) => {
83 const reader = readableStream.getReader();
@@ -53,90 +48,4 @@ function traceRaw(x) {
5348 return x;
5449}
5550
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−
51+module.exports = { readStream, getStorage, getFileName, trace, traceRaw };
Haskell Language Server.novaextension/Syntaxes/Haskell.xml+10−29
@@ -65,6 +65,7 @@
6565
6666 <template-scopes>
6767 <include syntax="self" collection="Quote" />
68+ <include syntax="self" collection="comments" />
6869 </template-scopes>
6970
7071 <collections>
@@ -136,7 +137,6 @@
136137 <capture number="1" name="haskell.pattern.record.bracket" />
137138 </ends-with>
138139 <subscopes>
139− <include syntax="self" collection="comments" />
140140 <include syntax="self" collection="expressions" />
141141 <scope name="record-sep">
142142 <expression>=</expression>
@@ -159,7 +159,6 @@
159159 <capture number="1" name="haskell.pattern.record.bracket" />
160160 </ends-with>
161161 <subscopes>
162− <include syntax="self" collection="comments" />
163162 <scope name="haskell.pattern.record.wildcard">
164163 <expression>\.\.</expression>
165164 </scope>
@@ -186,7 +185,6 @@
186185 <capture number="1" name="haskell.list.bracket" />
187186 </ends-with>
188187 <subscopes>
189− <include syntax="self" collection="comments" />
190188 <include syntax="self" collection="expressions" />
191189 </subscopes>
192190 </scope>
@@ -241,7 +239,6 @@
241239 <capture number="1" name="haskell.tuple.bracket" />
242240 </ends-with>
243241 <subscopes>
244− <include syntax="self" collection="comments" />
245242 <include syntax="self" collection="expressions" />
246243 </subscopes>
247244 </scope>
@@ -266,7 +263,6 @@
266263 <expression>(?=(where|^\s*$))</expression>
267264 </ends-with>
268265 <subscopes>
269− <include syntax="self" collection="comments" />
270266 <include syntax="self" collection="type" />
271267 </subscopes>
272268 </scope>
@@ -346,7 +342,6 @@
346342 <template>^(?!\s+\1\S)(?!\s*$)</template>
347343 </ends-with>
348344 <subscopes>
349− <include syntax="self" collection="comments" />
350345 <include syntax="self" collection="type" optional="true" repeat="true" />
351346 <scope>
352347 <expression>=</expression>
@@ -370,7 +365,6 @@
370365 <template>^(?!\1\3\s)(?!\s+\1\S)(?!\s*$)</template>
371366 </ends-with>
372367 <subscopes>
373− <include syntax="self" collection="comments" />
374368 <include syntax="self" collection="type-annotation" />
375369 <include syntax="self" collection="implementation" />
376370 </subscopes>
@@ -388,7 +382,6 @@
388382 <template>^(?!\1\3\s)(?!\s+\1\S)(?!\s*$)</template>
389383 </ends-with>
390384 <subscopes>
391− <include syntax="self" collection="comments" />
392385 <include syntax="self" collection="pattern-match" optional="true" repeat="true" />
393386 <scope>
394387 <expression>=</expression>
@@ -410,7 +403,6 @@
410403 <template>^(?!\s+\1\S)(?!\s*$)</template>
411404 </ends-with>
412405 <subscopes>
413− <include syntax="self" collection="comments" />
414406 <include syntax="self" collection="type" />
415407 </subscopes>
416408 </scope>
@@ -430,7 +422,6 @@
430422 <template>^(?!\s+\1\S)(?!\s*$)</template>
431423 </ends-with>
432424 <subscopes>
433− <include syntax="self" collection="comments" />
434425 <include syntax="self" collection="type" />
435426 </subscopes>
436427 </scope>
@@ -450,7 +441,6 @@
450441 <template>^(?!\s+\1\S)(?!\s*$)</template>
451442 </ends-with>
452443 <subscopes>
453− <include syntax="self" collection="comments" />
454444 <scope name="haskell.keyword.construct.where">
455445 <expression>where</expression>
456446 </scope>
@@ -484,7 +474,6 @@
484474 <expression>deriving(\h+(newtype|stock|anyclass))?</expression>
485475 </scope>
486476 <scope name="haskell.record.construct.deriving.keyword">
487− <include syntax="self" collection="comments" />
488477 <expression>via</expression>
489478 </scope>
490479 </collection>
@@ -503,7 +492,6 @@
503492 <capture number="1" name="haskell.record.bracket" />
504493 </ends-with>
505494 <subscopes>
506− <include syntax="self" collection="comments" />
507495 <include syntax="self" collection="record-definition-field-name" />
508496 <include syntax="self" collection="type" />
509497 </subscopes>
@@ -535,7 +523,6 @@
535523 <expression>\)</expression>
536524 </ends-with>
537525 <subscopes>
538− <include syntax="self" collection="comments" />
539526 <scope name="haskell.construct.type.typle.comma">
540527 <expression>\,</expression>
541528 </scope>
@@ -550,7 +537,6 @@
550537 <expression>\]</expression>
551538 </ends-with>
552539 <subscopes>
553− <include syntax="self" collection="comments" />
554540 <include syntax="self" collection="type" />
555541 </subscopes>
556542 </scope>
@@ -585,7 +571,6 @@
585571 <template>^(?!\s+\1\S)(?!\s*$)</template>
586572 </ends-with>
587573 <subscopes>
588− <include syntax="self" collection="comments" />
589574 <scope name="haskell.keyword.construct.where">
590575 <expression>where</expression>
591576 </scope>
@@ -605,7 +590,6 @@
605590 <capture number="1" name="haskell.type-list.bracket" />
606591 </ends-with>
607592 <subscopes>
608− <include syntax="self" collection="comments" />
609593 <include syntax="self" collection="type" />
610594 </subscopes>
611595 </scope>
@@ -622,7 +606,6 @@
622606 <capture number="1" name="haskell.keyword.construct.lambda" />
623607 </ends-with>
624608 <subscopes>
625− <include syntax="self" collection="comments" />
626609 <include syntax="self" collection="pattern-match" />
627610 </subscopes>
628611 </scope>
@@ -644,7 +627,6 @@
644627 <template>^(?!\1\s*\S)(?!s*$)</template>
645628 </ends-with>
646629 <subscopes>
647− <include syntax="self" collection="comments" />
648630 <include syntax="self" collection="definition" />
649631 </subscopes>
650632 </scope>
@@ -684,12 +666,12 @@
684666
685667
686668 <collection name="strings">
687− <scope name="haskell.string.double-quoted" spell-check="true">
669+ <scope name="haskell.string.double-quoted">
688670 <starts-with>
689− <expression>&quot;</expression>
671+ <expression>"</expression>
690672 </starts-with>
691673 <ends-with>
692− <expression>&quot;</expression>
674+ <expression>"</expression>
693675 </ends-with>
694676 <subscopes>
695677 <scope name="haskell.string.escape-sequences">
@@ -726,7 +708,6 @@
726708 </ends-with>
727709 <subscopes>
728710 <scope name="identifier.haskell.type">
729− <symbol type="expression" />
730711 <symbol type="expression" />
731712 <expression>([A-Z](\w|')*)\h*(\(\h*\.\.\h*\))?</expression>
732713 <capture number="1" name="identifier.type" />
@@ -751,7 +732,6 @@
751732 </ends-with>
752733 <subscopes>
753734 <scope name="haskell.construct.qualified">
754− <symbol type="expression" />
755735 <expression>qualified</expression>
756736 <capture number="0" name="haskell.construct.keyword.qualified" />
757737 </scope>
@@ -769,7 +749,6 @@
769749 </ends-with>
770750 <subscopes anchored="true">
771751 <include syntax="self" collection="import-list" />
772− <symbol type="expression" />
773752 </subscopes>
774753 </scope>
775754
@@ -803,7 +782,6 @@
803782 </ends-with>
804783 <subscopes>
805784 <scope name="haskell.identifier.struct">
806− <symbol type="expression" />
807785 <symbol type="reference" scope="local" />
808786 <expression>([A-Z](\w|')*)\h*(\(\h*\.\.\h*\))?</expression>
809787 <capture number="1" name="haskell.import-list.identifier.type.name" />
@@ -873,11 +851,14 @@
873851
874852 <collection name="comments">
875853 <scope name="haskell.comment.single" spell-check="true">
876− <symbol type="comment" />
877− <expression> --.*$</expression>
854+ <starts-with>
855+ <expression>--</expression>
856+ </starts-with>
857+ <ends-with>
858+ <expression>$</expression>
859+ </ends-with>
878860 </scope>
879861 <scope name="haskell.comment.block" spell-check="true">
880− <symbol type="comment" />
881862 <starts-with>
882863 <expression>{-</expression>
883864 </starts-with>
Haskell Language Server.novaextension/extension.json−8
@@ -20,14 +20,6 @@
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− },
3123 {
3224 "type": "section",
3325 "title": "Haskell Language Server settings",