-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,18 @@ import { AutoInsertRequest, FindFileReferenceRequest, ShowReferencesNotification | |
import { CancellationTokenHost } from '../cancellationPipe'; | ||
import type { Workspaces } from '../workspaces'; | ||
import * as shared from '@volar/shared'; | ||
import { RuntimeEnvironment } from '../../types'; | ||
import { RuntimeEnvironment, LanguageServerInitializationOptions } from '../../types'; | ||
import { createDocuments } from '../documents'; | ||
|
||
export function register( | ||
connection: vscode.Connection, | ||
projects: Workspaces, | ||
initParams: vscode.InitializeParams, | ||
initOptions: LanguageServerInitializationOptions, | ||
cancelHost: CancellationTokenHost, | ||
semanticTokensLegend: vscode.SemanticTokensLegend, | ||
runtime: RuntimeEnvironment, | ||
documents: ReturnType<typeof createDocuments>, | ||
) { | ||
|
||
let lastCompleteUri: string; | ||
|
@@ -71,15 +74,39 @@ export function register( | |
return worker(params.textDocument.uri, token, async service => { | ||
lastCompleteUri = params.textDocument.uri; | ||
lastCompleteLs = service; | ||
const document = documents.data.uriGet(params.textDocument.uri)?.getDocument(); | ||
const list = await service.doComplete( | ||
params.textDocument.uri, | ||
params.position, | ||
params.context, | ||
); | ||
if (list) { | ||
for (const item of list.items) { | ||
fixTextEdit(item); | ||
} | ||
for (const item of list.items) { | ||
fixTextEdit(item); | ||
} | ||
if (!initOptions.fullCompletionList && document) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rchl
Contributor
|
||
list.items = list.items.filter(item => { | ||
const range = item.textEdit ? ( | ||
vscode.InsertReplaceEdit.is(item.textEdit) ? item.textEdit.replace : | ||
item.textEdit.range | ||
) : list.itemDefaults?.editRange ? ( | ||
vscode.Range.is(list.itemDefaults.editRange) ? list.itemDefaults.editRange : | ||
list.itemDefaults.editRange.replace | ||
) : undefined; | ||
if (range) { | ||
const sourceText = document.getText(range).toLowerCase(); | ||
if (sourceText.trim()) { | ||
let filterText = (item.filterText ?? item.label).toLowerCase(); | ||
for (const char of sourceText) { | ||
const index = filterText.indexOf(char); | ||
if (index === -1) { | ||
return false; | ||
} | ||
filterText = filterText.slice(index + 1); | ||
} | ||
} | ||
return true; | ||
} | ||
}); | ||
} | ||
return list; | ||
}); | ||
|
Why is it implemented as an option? Are there caveats to using it? It would be good to explain as I don't know as an user what effect will it have. Will I miss some completions?
Also, is the issue mostly caused by Typescript? If so, shouldn't those be filtered out at the place where those are generated?