Skip to content

Commit

Permalink
Merge branch 'clangd:master' into disabled-api
Browse files Browse the repository at this point in the history
  • Loading branch information
thegecko committed Nov 15, 2024
2 parents e18c97a + 0cda54a commit 287653e
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 68 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
11 changes: 0 additions & 11 deletions api/vscode-clangd.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -23,7 +13,6 @@ export interface ClangdApiV2 {

export interface ClangdExtension {
getApi(version: 1): ClangdApiV1;
getApi(version: 2): ClangdApiV2;
}

// clangd custom request types
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down Expand Up @@ -397,4 +397,4 @@
]
}
}
}
}
9 changes: 2 additions & 7 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -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`);
Expand Down
88 changes: 47 additions & 41 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>('arguments'),
options: {cwd: vscode.workspace.rootPath || process.cwd(), shell: true}
options: {cwd: vscode.workspace.rootPath || process.cwd()}
};
const traceFile = config.get<string>('trace');
if (!!traceFile) {
Expand Down Expand Up @@ -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<boolean>('enableCodeCompletion'))
return new vscode.CompletionList([], /*isIncomplete=*/ false);
let list = await next(document, position, context, token);
if (!config.get<boolean>('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<boolean>('enableCodeCompletion'))
return new vscode.CompletionList([], /*isIncomplete=*/ false);
let list = await next(document, position, context, token);
if (!config.get<boolean>('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<boolean>('enableHover'))
return null;
Expand Down
5 changes: 3 additions & 2 deletions src/inactive-regions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class UI {
}

get clangdPath(): string {
let p = config.get<string>('path')!;
let p = config.get<string>('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) &&
Expand Down

0 comments on commit 287653e

Please sign in to comment.