Skip to content

Commit 79449d6

Browse files
authored
Merge pull request #61 from CodinGame/hotfix-clangd
[FIX] Hotfix clangd
2 parents 4aeb54a + 99cc667 commit 79449d6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/staticOptions.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
import * as vscode from 'vscode'
22
import * as monaco from 'monaco-editor'
3+
import { Middleware } from 'monaco-languageclient'
34
import type { LanguageClientOptions } from './languageClientOptions'
45

56
type LanguageClientOptionsById<T extends string> = Record<T, LanguageClientOptions>
67
const asLanguageClientOptionsById = <K extends string> (options: LanguageClientOptionsById<K>): LanguageClientOptionsById<K> => options
78

9+
const clangdHotfixMiddleware: Middleware = {
10+
async provideCompletionItem (document, position, context, token, next) {
11+
const list = await next(document, position, context, token)
12+
// Hotfix (see https://github.com/clangd/vscode-clangd/blob/df56a9a058fca773eb4c096d0f6a5a31b71b79d7/src/clangd-context.ts#L124)
13+
const items = Array.isArray(list) ? list : list?.items
14+
if (items != null) {
15+
for (const item of items) {
16+
item.commitCharacters = []
17+
}
18+
}
19+
return list
20+
}
21+
}
22+
823
const staticOptions = asLanguageClientOptionsById({
924
angular: {
1025
documentSelector: [
@@ -31,6 +46,7 @@ const staticOptions = asLanguageClientOptionsById({
3146
{ scheme: 'file', language: 'c' },
3247
{ scheme: 'file', language: 'cpp' }
3348
],
49+
middleware: clangdHotfixMiddleware,
3450
mutualizable: false
3551
// The extension is cpptools BUT the language server is unable to use the client configuration (it requires client code)
3652
// vscodeExtensionIds: ['cpptools']
@@ -71,6 +87,7 @@ const staticOptions = asLanguageClientOptionsById({
7187
{ scheme: 'file', language: 'cpp' },
7288
{ scheme: 'file', language: 'cuda-cpp' }
7389
],
90+
middleware: clangdHotfixMiddleware,
7491
mutualizable: false
7592
// The extension is cpptools BUT the language server is unable to use the client configuration (it requires client code)
7693
// vscodeExtensionIds: ['cpptools']
@@ -221,6 +238,7 @@ const staticOptions = asLanguageClientOptionsById({
221238
{ scheme: 'file', language: 'cpp' },
222239
{ scheme: 'file', language: 'objective-c' }
223240
],
241+
middleware: clangdHotfixMiddleware,
224242
mutualizable: false
225243
// The extension is cpptools BUT the language server is unable to use the client configuration (it requires client code)
226244
// vscodeExtensionIds: ['cpptools']

0 commit comments

Comments
 (0)