diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d4e850..c0d2344 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## Version 0.1.31: November 13, 2024 + +* Reverted [#708](https://github.com/clangd/vscode-clangd/pull/708) and [#715](https://github.com/clangd/vscode-clangd/pull/715) for causing [#722](https://github.com/clangd/vscode-clangd/issues/722) + + ## Version 0.1.30: November 13, 2024 * Added option to disable hovers [#703](https://github.com/clangd/vscode-clangd/pull/703) diff --git a/api/README.md b/api/README.md index a35c068..f752fc5 100644 --- a/api/README.md +++ b/api/README.md @@ -7,7 +7,7 @@ import * as vscode from 'vscode'; import type { ClangdExtension, ASTParams, ASTNode } from '@clangd/vscode-clangd'; const CLANGD_EXTENSION = 'llvm-vs-code-extensions.vscode-clangd'; -const CLANGD_API_VERSION = 2; +const CLANGD_API_VERSION = 1; const ASTRequestMethod = 'textDocument/ast'; diff --git a/api/vscode-clangd.d.ts b/api/vscode-clangd.d.ts index 56d34bd..0a3a9b2 100644 --- a/api/vscode-clangd.d.ts +++ b/api/vscode-clangd.d.ts @@ -2,16 +2,6 @@ import {BaseLanguageClient} from 'vscode-languageclient'; import * as vscodelc from 'vscode-languageclient/node'; export interface ClangdApiV1 { - // vscode-clangd's language client which can be used to send requests to the - // clangd language server - // Standard requests: - // https://microsoft.github.io/language-server-protocol/specifications/specification-current - // clangd custom requests: - // https://clangd.llvm.org/extensions - languageClient: BaseLanguageClient; -} - -export interface ClangdApiV2 { // vscode-clangd's language client which can be used to send requests to the // clangd language server // Standard requests: @@ -23,7 +13,6 @@ export interface ClangdApiV2 { export interface ClangdExtension { getApi(version: 1): ClangdApiV1; - getApi(version: 2): ClangdApiV2; } // clangd custom request types diff --git a/package-lock.json b/package-lock.json index db76562..11fa3d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-clangd", - "version": "0.1.30", + "version": "0.1.31", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vscode-clangd", - "version": "0.1.30", + "version": "0.1.31", "license": "MIT", "dependencies": { "@clangd/install": "0.1.17", @@ -5848,4 +5848,4 @@ "dev": true } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 1923d11..b92d3d7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-clangd", "displayName": "clangd", "description": "C/C++ completion, navigation, and insights", - "version": "0.1.30", + "version": "0.1.31", "publisher": "llvm-vs-code-extensions", "license": "MIT", "homepage": "https://clangd.llvm.org/", @@ -397,4 +397,4 @@ ] } } -} \ No newline at end of file +} diff --git a/src/api.ts b/src/api.ts index 40a3b40..114e94c 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,19 +1,14 @@ import {BaseLanguageClient} from 'vscode-languageclient'; -import {ClangdApiV1, ClangdApiV2, ClangdExtension} from '../api/vscode-clangd'; +import {ClangdApiV1, ClangdExtension} from '../api/vscode-clangd'; export class ClangdExtensionImpl implements ClangdExtension { constructor(public client: BaseLanguageClient|undefined) {} public getApi(version: 1): ClangdApiV1; - public getApi(version: 2): ClangdApiV2; public getApi(version: number): unknown { - switch (version) { - case 1: - case 2: { + if (version === 1) { return {languageClient: this.client}; - break; - } } throw new Error(`No API version ${version} found`); diff --git a/src/clangd-context.ts b/src/clangd-context.ts index 5e697ea..064395f 100644 --- a/src/clangd-context.ts +++ b/src/clangd-context.ts @@ -67,11 +67,9 @@ export class ClangdContext implements vscode.Disposable { return; const clangd: vscodelc.Executable = { - // Quote the path. With `shell: true`, this is needed - // in case the path contains spaces. - command: `"${clangdPath}"`, + command: clangdPath, args: await config.get('arguments'), - options: {cwd: vscode.workspace.rootPath || process.cwd(), shell: true} + options: {cwd: vscode.workspace.rootPath || process.cwd()} }; const traceFile = config.get('trace'); if (!!traceFile) { @@ -106,43 +104,51 @@ export class ClangdContext implements vscode.Disposable { // We also mark the list as incomplete to force retrieving new rankings. // See https://github.com/microsoft/language-server-protocol/issues/898 middleware: { - provideCompletionItem: async (document, position, context, token, - next) => { - if (!config.get('enableCodeCompletion')) - return new vscode.CompletionList([], /*isIncomplete=*/ false); - let list = await next(document, position, context, token); - if (!config.get('serverCompletionRanking')) - return list; - let items = (Array.isArray(list) ? list : list!.items).map(item => { - // Gets the prefix used by VSCode when doing fuzzymatch. - let prefix = document.getText( - new vscode.Range((item.range as vscode.Range).start, position)) - if (prefix) - item.filterText = prefix + '_' + item.filterText; - // Workaround for https://github.com/clangd/vscode-clangd/issues/357 - // clangd's used of commit-characters was well-intentioned, but - // overall UX is poor. Due to vscode-languageclient bugs, we didn't - // notice until the behavior was in several releases, so we need - // to override it on the client. - item.commitCharacters = []; - // VSCode won't automatically trigger signature help when entering - // a placeholder, e.g. if the completion inserted brackets and - // placed the cursor inside them. - // https://github.com/microsoft/vscode/issues/164310 - // They say a plugin should trigger this, but LSP has no mechanism. - // https://github.com/microsoft/language-server-protocol/issues/274 - // (This workaround is incomplete, and only helps the first param). - if (item.insertText instanceof vscode.SnippetString && - !item.command && - item.insertText.value.match(/[([{<,] ?\$\{?[01]\D/)) - item.command = { - title: 'Signature help', - command: 'editor.action.triggerParameterHints' - }; - return item; - }) - return new vscode.CompletionList(items, /*isIncomplete=*/ true); - }, + provideCompletionItem: + async (document, position, context, token, next) => { + if (!config.get('enableCodeCompletion')) + return new vscode.CompletionList([], /*isIncomplete=*/ false); + let list = await next(document, position, context, token); + if (!config.get('serverCompletionRanking')) + return list; + let items = + (!list ? [] + : Array.isArray(list) ? list + : list.items) + .map(item => { + // Gets the prefix used by VSCode when doing fuzzymatch. + let prefix = document.getText(new vscode.Range( + (item.range as vscode.Range).start, position)) + if (prefix) + item.filterText = prefix + '_' + item.filterText; + // Workaround for + // https://github.com/clangd/vscode-clangd/issues/357 + // clangd's used of commit-characters was + // well-intentioned, but overall UX is poor. Due to + // vscode-languageclient bugs, we didn't notice until + // the behavior was in several releases, so we need to + // override it on the client. + item.commitCharacters = []; + // VSCode won't automatically trigger signature help + // when entering a placeholder, e.g. if the completion + // inserted brackets and placed the cursor inside them. + // https://github.com/microsoft/vscode/issues/164310 + // They say a plugin should trigger this, but LSP has no + // mechanism. + // https://github.com/microsoft/language-server-protocol/issues/274 + // (This workaround is incomplete, and only helps the + // first param). + if (item.insertText instanceof vscode.SnippetString && + !item.command && + item.insertText.value.match(/[([{<,] ?\$\{?[01]\D/)) + item.command = { + title: 'Signature help', + command: 'editor.action.triggerParameterHints' + }; + return item; + }) + return new vscode.CompletionList(items, /*isIncomplete=*/ true); + }, provideHover: async (document, position, token, next) => { if (!config.get('enableHover')) return null; diff --git a/src/inactive-regions.ts b/src/inactive-regions.ts index 6cb4bc6..3ed7368 100644 --- a/src/inactive-regions.ts +++ b/src/inactive-regions.ts @@ -85,9 +85,10 @@ export class InactiveRegionsFeature implements vscodelc.StaticFeature { if (!this.context.client) { return; } + const converter = this.context.client.protocol2CodeConverter; const filePath = vscode.Uri.parse(params.textDocument.uri, true).fsPath; - const ranges: vscode.Range[] = params.regions.map( - (r) => this.context.client!.protocol2CodeConverter.asRange(r)); + const ranges: vscode.Range[] = + params.regions.map((r) => converter.asRange(r)); this.files.set(filePath, ranges); this.applyHighlights(filePath); } diff --git a/src/install.ts b/src/install.ts index d9c3bd8..c4ea8f9 100644 --- a/src/install.ts +++ b/src/install.ts @@ -121,7 +121,7 @@ class UI { } get clangdPath(): string { - let p = config.get('path')!; + let p = config.get('path'); // Backwards compatibility: if it's a relative path with a slash, interpret // relative to project root. if (!path.isAbsolute(p) && p.includes(path.sep) &&