Skip to content

Commit b1c894a

Browse files
committed
Use enumeration to choose beteen hie, hls or ghcide
1 parent dd6eaa6 commit b1c894a

File tree

5 files changed

+49
-107
lines changed

5 files changed

+49
-107
lines changed

Changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### 0.0.40
2+
3+
Change the way the backend is configured, simplifying it.
4+
5+
* remove wrapper scripts (hie-vscode.sh/hie-vscode.bat)
6+
* dropdown choice between `haskell-ide-engine`, `haskell-language-server` or
7+
`ghcide` in the `hieVariant` setting.
8+
* this can be overridden by an explicit `hieExecutablePath`, as before.
9+
110
### 0.0.39
211

312
Remove verbose logging option, it is not longer supported.

hie-vscode.bat

Lines changed: 0 additions & 21 deletions
This file was deleted.

hie-vscode.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

package.json

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-hie-server",
33
"displayName": "Haskell Language Server",
44
"description": "Language Server Protocol for Haskell via HIE",
5-
"version": "0.0.39",
5+
"version": "0.0.40",
66
"license": "MIT",
77
"publisher": "alanz",
88
"engines": {
@@ -88,33 +88,6 @@
8888
"default": "brittany",
8989
"description": "The tool to use for formatting requests."
9090
},
91-
"languageServerHaskell.hieExecutablePath": {
92-
"scope": "resource",
93-
"type": "string",
94-
"default": "",
95-
"description":
96-
"Set the path to your hie executable, if it's not already on your $PATH. Works with ~, ${HOME} and ${workspaceFolder}."
97-
},
98-
"languageServerHaskell.useCustomHieWrapper": {
99-
"scope": "resource",
100-
"type": "boolean",
101-
"default": false,
102-
"description":
103-
"Use your own custom wrapper for hie (remember to specify the path!). This will take precedence over useHieWrapper and hieExecutablePath."
104-
},
105-
"languageServerHaskell.useCustomHieWrapperPath": {
106-
"scope": "resource",
107-
"type": "string",
108-
"default": "",
109-
"description":
110-
"Specify the full path to your own custom hie wrapper (e.g. ${HOME}/.hie-wrapper.sh). Works with ~, ${HOME} and ${workspaceFolder}."
111-
},
112-
"languageServerHaskell.noLspParam": {
113-
"scope": "resource",
114-
"type": "boolean",
115-
"default": false,
116-
"description": "Do not set the '--lsp' flag in the hie/hie-wrapper arguments when launching it"
117-
},
11891
"languageServerHaskell.showTypeForSelection.onHover": {
11992
"scope": "resource",
12093
"type": "boolean",
@@ -143,6 +116,20 @@
143116
"default": "",
144117
"description": "If set, redirects the logs to a file."
145118
},
119+
"languageServerHaskell.hieVariant": {
120+
"scope": "resource",
121+
"type": "string",
122+
"enum": ["haskell-ide-engine", "haskell-language-server", "ghcide"],
123+
"default": "haskell-ide-engine",
124+
"description": "Which hasell language server to use."
125+
},
126+
"languageServerHaskell.hieExecutablePath": {
127+
"scope": "resource",
128+
"type": "string",
129+
"default": "",
130+
"description":
131+
"Set the path to your hie executable, if it's not already on your $PATH. Works with ~, ${HOME} and ${workspaceFolder}."
132+
},
146133
"languageServerHaskell.enableHIE": {
147134
"scope": "resource",
148135
"type": "boolean",

src/extension.ts

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22
import * as child_process from 'child_process';
33
import * as os from 'os';
4-
import * as path from 'path';
54
import {
65
commands,
76
ExtensionContext,
@@ -69,13 +68,13 @@ async function activateHie(context: ExtensionContext, document: TextDocument) {
6968
}
7069

7170
try {
72-
const useCustomWrapper = workspace.getConfiguration('languageServerHaskell', uri).useCustomHieWrapper;
7371
const hieExecutablePath = workspace.getConfiguration('languageServerHaskell', uri).hieExecutablePath;
7472
// Check if hie is installed.
75-
if (!await isHieInstalled() && !useCustomWrapper && hieExecutablePath === '') {
73+
const exeName = 'hie';
74+
if (!await isHieInstalled(exeName) && hieExecutablePath === '') {
7675
// TODO: Once haskell-ide-engine is on hackage/stackage, enable an option to install it via cabal/stack.
7776
const notInstalledMsg: string =
78-
'hie executable missing, please make sure it is installed, see github.com/haskell/haskell-ide-engine.';
77+
exeName + ' executable missing, please make sure it is installed, see github.com/haskell/haskell-ide-engine.';
7978
const forceStart: string = 'Force Start';
8079
window.showErrorMessage(notInstalledMsg, forceStart).then(option => {
8180
if (option === forceStart) {
@@ -104,22 +103,13 @@ function activateHieNoCheck(context: ExtensionContext, folder: WorkspaceFolder,
104103
docsBrowserRegistered = true;
105104
}
106105

107-
const useCustomWrapper = workspace.getConfiguration('languageServerHaskell', uri).useCustomHieWrapper;
106+
const hieVariant = workspace.getConfiguration('languageServerHaskell', uri).hieVariant;
108107
let hieExecutablePath = workspace.getConfiguration('languageServerHaskell', uri).hieExecutablePath;
109-
let customWrapperPath = workspace.getConfiguration('languageServerHaskell', uri).useCustomHieWrapperPath;
110-
const noLspParam = workspace.getConfiguration('languageServerHaskell', uri).noLspParam;
111108
const logLevel = workspace.getConfiguration('languageServerHaskell', uri).trace.server;
112109
const logFile = workspace.getConfiguration('languageServerHaskell', uri).logFile;
113110

114111
// Substitute path variables with their corresponding locations.
115-
if (useCustomWrapper) {
116-
customWrapperPath = customWrapperPath
117-
.replace('${workspaceFolder}', folder.uri.path)
118-
.replace('${workspaceRoot}', folder.uri.path)
119-
.replace('${HOME}', os.homedir)
120-
.replace('${home}', os.homedir)
121-
.replace(/^~/, os.homedir);
122-
} else if (hieExecutablePath !== '') {
112+
if (hieExecutablePath !== '') {
123113
hieExecutablePath = hieExecutablePath
124114
.replace('${workspaceFolder}', folder.uri.path)
125115
.replace('${workspaceRoot}', folder.uri.path)
@@ -128,30 +118,33 @@ function activateHieNoCheck(context: ExtensionContext, folder: WorkspaceFolder,
128118
.replace(/^~/, os.homedir);
129119
}
130120

131-
// Set the executable, based on the settings. The order goes: First
132-
// check useCustomWrapper, then check hieExecutablePath, else retain
133-
// original path.
134-
let hieLaunchScript = process.platform === 'win32' ? 'hie-vscode.bat' : 'hie-vscode.sh';
135-
if (useCustomWrapper) {
136-
hieLaunchScript = customWrapperPath;
137-
} else if (hieExecutablePath !== '') {
121+
// Set the executable, based on the settings.
122+
let hieLaunchScript = 'hie'; // should get set below
123+
switch (hieVariant) {
124+
case 'haskell-ide-engine':
125+
hieLaunchScript = 'hie-wrapper';
126+
break;
127+
case 'haskell-language-server':
128+
hieLaunchScript = 'haskell-language-server-wrapper';
129+
break;
130+
case 'ghcide':
131+
hieLaunchScript = 'ghcide';
132+
break;
133+
}
134+
if (hieExecutablePath !== '') {
138135
hieLaunchScript = hieExecutablePath;
139136
}
140137

141138
// If using a custom wrapper or specificed an executable path, the path is assumed to already
142139
// be absolute.
143-
const serverPath =
144-
useCustomWrapper || hieExecutablePath ? hieLaunchScript : context.asAbsolutePath(path.join('.', hieLaunchScript));
140+
const serverPath = hieLaunchScript;
145141

146-
const runArgs: string[] = [];
147-
let debugArgs: string[] = [];
142+
const runArgs: string[] = ['--lsp'];
143+
let debugArgs: string[] = ['--lsp'];
148144
if (logLevel === 'messages') {
149145
debugArgs = ['-d'];
150146
}
151-
if (!noLspParam) {
152-
runArgs.unshift('--lsp');
153-
debugArgs.unshift('--lsp');
154-
}
147+
155148
if (logFile !== '') {
156149
debugArgs = debugArgs.concat(['-l', logFile]);
157150
}
@@ -242,9 +235,9 @@ export function deactivate(): Thenable<void> {
242235
/*
243236
* Check if HIE is installed.
244237
*/
245-
async function isHieInstalled(): Promise<boolean> {
238+
async function isHieInstalled(exeName: string): Promise<boolean> {
246239
return new Promise<boolean>((resolve, reject) => {
247-
const cmd: string = process.platform === 'win32' ? 'where hie' : 'which hie';
240+
const cmd: string = process.platform === 'win32' ? 'where ' + exeName : 'which ' + exeName;
248241
child_process.exec(cmd, (error, stdout, stderr) => resolve(!error));
249242
});
250243
}

0 commit comments

Comments
 (0)