Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevinswiber/38274d0b962463490d4e3d19d44e7ccc to your computer and use it in GitHub Desktop.
Save kevinswiber/38274d0b962463490d4e3d19d44e7ccc to your computer and use it in GitHub Desktop.
Patches for yaml-language-server and spectral-language-server to work with Neovim's lsp and lsp-config
Changing configuration.workspaceFolder to connection.workspace.getWorkspaceFolders() to support non-VSCode workspace folders.
diff --git a/dist/spectral-language-server/src/server.js b/dist/spectral-language-server/src/server.js
index 8878d95..7ec85d6 100644
--- a/dist/spectral-language-server/src/server.js
+++ b/dist/spectral-language-server/src/server.js
@@ -118,19 +118,21 @@ function resolveSettings(document) {
}
let rulesetFile = null;
connection.console.log(`Using ruleset file: ${configuration.rulesetFile}.`);
+ const workspaceFolder = (await connection.workspace.getWorkspaceFolders())[0];
let rulesetFileIsUrl = false;
if (configuration.rulesetFile) {
const ruleSetUri = vscode_uri_1.URI.parse(configuration.rulesetFile);
rulesetFileIsUrl = vscode_uri_1.URI.isUri(ruleSetUri) && (ruleSetUri.scheme === 'https' || ruleSetUri.scheme === 'http');
- if (configuration.workspaceFolder && !rulesetFileIsUrl) {
- rulesetFile = path.resolve((_a = getDocumentPath(configuration.workspaceFolder.uri)) !== null && _a !== void 0 ? _a : '', configuration.rulesetFile);
+ if (workspaceFolder && !rulesetFileIsUrl) {
+ rulesetFile = path.resolve((_a = getDocumentPath(workspaceFolder.uri)) !== null && _a !== void 0 ? _a : '', configuration.rulesetFile);
}
else {
rulesetFile = configuration.rulesetFile;
}
}
else {
- rulesetFile = (_c = (await getDefaultRulesetFile((_b = configuration.workspaceFolder) === null || _b === void 0 ? void 0 : _b.uri))) !== null && _c !== void 0 ? _c : null;
+ connection.console.log(`Workspace folder: ${workspaceFolder || 'none'}`)
+ rulesetFile = (_c = (await getDefaultRulesetFile((_b = workspaceFolder) === null || _b === void 0 ? void 0 : _b.uri))) !== null && _c !== void 0 ? _c : null;
}
if (rulesetFile && (rulesetFileIsUrl || fs.existsSync(rulesetFile))) {
if (docPath === rulesetFile) {
Fixing array length check to support working in non-VSCode environments.
diff --git a/src/languageservice/services/yamlCompletion.ts b/src/languageservice/services/yamlCompletion.ts
index 99e061f..c2cff16 100644
--- a/src/languageservice/services/yamlCompletion.ts
+++ b/src/languageservice/services/yamlCompletion.ts
@@ -293,7 +293,7 @@ export class YamlCompletion {
proposed,
};
- if (this.customTags.length > 0) {
+ if (this.customTags && this.customTags.length > 0) {
this.getCustomTagValueCompletions(collector);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment