Skip to content

Commit 3c0421c

Browse files
committed
Add option to enable/disable .cabal file support
Support for `.cabal` files was implemented in HLS 2.0.0.0. But the vscode-haskell extension does not enable this Language Server support, because it would break for older HLS binaries, as these were unable to handle file updates for `.cabal` files. To work-around, we had a pre-release of the vscode-haskell plugin, which enabled support for `.cabal` plugins in an opt-in fashion. It's been a while, and we want to enable language server support for `.cabal` files unconditionally. There are still HLS binaries around that can't handle `.cabal` files, but it much less. For the unfortunate souls left behind with GHC versions such as 8.6.5, we add a new vscode-haskell option: haskell.supportCabalFiles This option is `true` by default, but if set to `false` it will unconditionally **disable** sending File Notifications for `.cabal` files, which allows us to keep working for older HLS binaries. This change would be difficult to test, and incur an, in my opinion, unreasonable price on our CI times. I manually tested the changes, by using HLS 1.8.0.0 (last released binary for GHC 8.6.5) on a project with `haskell.supportCabalFiles` set to `true` and `false` respectively. HLS seemed to behave correctly, showing Diagnostics for Haskell files, but not show any logs for `.cabal` files. The only potential change in behaviour is that vscode-haskell now also activates when a `.cabal` file has been opened. This may be overly eager to some, but since no Haskell files are typechecked, the impact on memory usage is negligible in my opinion.
1 parent ef0359e commit 3c0421c

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@
234234
"Prefer a multiple component session, if the build tool supports it. At the moment, only `cabal` supports multiple components session loading. If the `cabal` version does not support loading multiple components at once, we gracefully fall back to \"singleComponent\" mode."
235235
]
236236
},
237+
"haskell.supportCabalFiles": {
238+
"scope": "resource",
239+
"default": true,
240+
"type": "boolean",
241+
"description": "Enable Language Server support for `.cabal` files. Requires Haskell Language Server version >= 2.0.0.0."
242+
},
237243
"haskell.maxCompletions": {
238244
"scope": "resource",
239245
"default": 40,

src/extension.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ async function activateServerForFolder(context: ExtensionContext, uri: Uri, fold
205205
args = args.concat(extraArgs.split(' '));
206206
}
207207

208+
const cabalFileSupport: boolean = workspace.getConfiguration('haskell', uri).supportCabalFiles;
209+
logger.info(`Support for '.cabal' files enabled: ${cabalFileSupport ? 'yes' : 'no'}`);
210+
208211
// If we're operating on a standalone file (i.e. not in a folder) then we need
209212
// to launch the server in a reasonable current directory. Otherwise the cradle
210213
// guessing logic in hie-bios will be wrong!
@@ -253,14 +256,21 @@ async function activateServerForFolder(context: ExtensionContext, uri: Uri, fold
253256

254257
const pat = folder ? `${folder.uri.fsPath}/**/*` : '**/*';
255258
logger.log(`document selector patten: ${pat}`);
259+
260+
261+
const cabalDocumentSelector = cabalFileSupport ? [{ scheme: 'file', language: 'cabal', pattern: pat }] : [];
262+
const haskellDocumentSelector = [
263+
{ scheme: 'file', language: 'haskell', pattern: pat },
264+
{ scheme: 'file', language: 'literate haskell', pattern: pat },
265+
];
266+
256267
const clientOptions: LanguageClientOptions = {
257268
// Use the document selector to only notify the LSP on files inside the folder
258269
// path for the specific workspace.
259-
documentSelector: [
260-
{ scheme: 'file', language: 'haskell', pattern: pat },
261-
{ scheme: 'file', language: 'literate haskell', pattern: pat },
262-
{ scheme: 'file', language: 'cabal', pattern: pat },
263-
],
270+
documentSelector:
271+
[ ... haskellDocumentSelector
272+
, ... cabalDocumentSelector
273+
],
264274
synchronize: {
265275
// Synchronize the setting section 'haskell' to the server.
266276
configurationSection: 'haskell',

0 commit comments

Comments
 (0)