on master help sign in
Start using path
commit3eb1500944c93789e528d9f2664b1acc8697cd43 authoriko <ilyakooo0@gmail.com> dateSat 19 Mar 2022, 20:07 (5 years ago) parent8350bc1
1 file changed+52−1
Haskell Language Server.novaextension/Scripts/download.js+52−1
Haskell Language Server.novaextension/Scripts/download.js+52−1
@@ -128,7 +128,7 @@ async function getGHCVersion() {
128128 sendPermanentNotification(
129129 tool + " not installed!",
130130 "Please install " + tool +
131− " and restart Haskell Language Server.",
131+ " and restart Haskell Language Server.",
132132 );
133133 } else {
134134 sendPermanentNotification("Couldn't detect GHC version", x);
@@ -141,7 +141,24 @@ async function getGHCVersion() {
141141 return promise;
142142}
143143async function getHLS() {
144+ const explicitPath = nova.workspace.config.get("haskell-language-server-path")
145+ if (explicitPath) {
146+ sendNotification("HLS path specified in settings", "Using the path to haskell-language-server specified in settings.")
147+ return explicitPath
148+ }
149+
144150 const version = await getGHCVersion();
151+ const localHLSPath = await which("haskell-language-server").catch((_) => null)
152+ if (localHLSPath) {
153+ sendNotification("Found HLS", "Found haskell-language-server in PATH. Checking if it is the right version.")
154+ const v = await getHLSVersion(localHLSPath)
155+ if (v === version) {
156+ sendNotification("Using local HLS", "The haskell-language-server in PATH has the right version. Using it.")
157+ return localHLSPath
158+ } else {
159+ sendNotification("Not using local HLS", "The haskell-language-server in PATH is built fot GHC " + v + " but we need GHC " + version + ". Trying other alternatives.")
160+ }
161+ }
145162 return await getTool(version);
146163}
147164
@@ -156,3 +173,37 @@ function getToolName(name) {
156173function notifyToolDownloading(name) {
157174 sendNotification("Downloading tool", "Downloading " + getToolName(name));
158175}
176+
177+function getHLSVersion(path) {
178+ return call(new Process(path, {
179+ args: ["--version"],
180+ }))
181+ .then((x) => x.match(/\(GHC: (\S+)\)/)[1].trim())
182+ .catch((err) => sendPermanentNotification("HLS version check failed", err))
183+}
184+
185+function which(name) {
186+ return call(new Process("/usr/bin/which", {
187+ args: [name],
188+ 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
209+}