Skip to content

Commit

Permalink
feat(lsp): inlineCompletion
Browse files Browse the repository at this point in the history
Closes #5071
  • Loading branch information
fannheyward committed Jul 23, 2024
1 parent 33d0a52 commit d8c5456
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 129 deletions.
40 changes: 22 additions & 18 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"eslint-plugin-jsdoc": "^48.5.0",
"jest": "29.7.0",
"typescript": "^5.5.3",
"vscode-languageserver": "^9.0.1"
"vscode-languageserver": "^10.0.0-next.7"
},
"dependencies": {
"@chemzqm/neovim": "^6.1.2",
Expand All @@ -108,9 +108,9 @@
"unidecode": "^1.0.1",
"unzip-stream": "^0.3.4",
"uuid": "^9.0.1",
"vscode-languageserver-protocol": "^3.17.5",
"vscode-languageserver-protocol": "^3.17.6-next.7",
"vscode-languageserver-textdocument": "^1.0.11",
"vscode-languageserver-types": "^3.17.5",
"vscode-languageserver-types": "^3.17.6-next.4",
"vscode-uri": "^3.0.8",
"which": "^4.0.0"
}
Expand Down
25 changes: 24 additions & 1 deletion src/__tests__/client/features.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert'
import path from 'path'
import { CallHierarchyIncomingCall, CallHierarchyItem, CallHierarchyOutgoingCall, CallHierarchyPrepareRequest, CancellationToken, CancellationTokenSource, CodeAction, CodeActionRequest, CodeLensRequest, Color, ColorInformation, ColorPresentation, CompletionItem, CompletionRequest, CompletionTriggerKind, ConfigurationRequest, DeclarationRequest, DefinitionRequest, DidChangeConfigurationNotification, DidChangeTextDocumentNotification, DidChangeWatchedFilesNotification, DidCloseTextDocumentNotification, DidCreateFilesNotification, DidDeleteFilesNotification, DidOpenTextDocumentNotification, DidRenameFilesNotification, DidSaveTextDocumentNotification, Disposable, DocumentColorRequest, DocumentDiagnosticReport, DocumentDiagnosticReportKind, DocumentDiagnosticRequest, DocumentFormattingRequest, DocumentHighlight, DocumentHighlightKind, DocumentHighlightRequest, DocumentLink, DocumentLinkRequest, DocumentOnTypeFormattingRequest, DocumentRangeFormattingRequest, DocumentSelector, DocumentSymbolRequest, FoldingRange, FoldingRangeRequest, FullDocumentDiagnosticReport, Hover, HoverRequest, ImplementationRequest, InlayHintKind, InlayHintLabelPart, InlayHintRequest, InlineValueEvaluatableExpression, InlineValueRequest, InlineValueText, InlineValueVariableLookup, LinkedEditingRangeRequest, Location, NotificationType0, ParameterInformation, Position, ProgressToken, ProtocolRequestType, Range, ReferencesRequest, RenameRequest, SelectionRange, SelectionRangeRequest, SemanticTokensRegistrationType, SignatureHelpRequest, SignatureHelpTriggerKind, SignatureInformation, TextDocumentEdit, TextDocumentSyncKind, TextEdit, TypeDefinitionRequest, TypeHierarchyPrepareRequest, WillCreateFilesRequest, WillDeleteFilesRequest, WillRenameFilesRequest, WillSaveTextDocumentNotification, WillSaveTextDocumentWaitUntilRequest, WorkDoneProgressBegin, WorkDoneProgressCreateRequest, WorkDoneProgressEnd, WorkDoneProgressReport, WorkspaceEdit, WorkspaceSymbolRequest } from 'vscode-languageserver-protocol'
import { CallHierarchyIncomingCall, CallHierarchyItem, CallHierarchyOutgoingCall, CallHierarchyPrepareRequest, CancellationToken, CancellationTokenSource, CodeAction, CodeActionRequest, CodeLensRequest, Color, ColorInformation, ColorPresentation, CompletionItem, CompletionRequest, CompletionTriggerKind, ConfigurationRequest, DeclarationRequest, DefinitionRequest, DidChangeConfigurationNotification, DidChangeTextDocumentNotification, DidChangeWatchedFilesNotification, DidCloseTextDocumentNotification, DidCreateFilesNotification, DidDeleteFilesNotification, DidOpenTextDocumentNotification, DidRenameFilesNotification, DidSaveTextDocumentNotification, Disposable, DocumentColorRequest, DocumentDiagnosticReport, DocumentDiagnosticReportKind, DocumentDiagnosticRequest, DocumentFormattingRequest, DocumentHighlight, DocumentHighlightKind, DocumentHighlightRequest, DocumentLink, DocumentLinkRequest, DocumentOnTypeFormattingRequest, DocumentRangeFormattingRequest, DocumentSelector, DocumentSymbolRequest, FoldingRange, FoldingRangeRequest, FullDocumentDiagnosticReport, Hover, HoverRequest, ImplementationRequest, InlayHintKind, InlayHintLabelPart, InlayHintRequest, InlineCompletionItem, InlineCompletionRequest, InlineValueEvaluatableExpression, InlineValueRequest, InlineValueText, InlineValueVariableLookup, LinkedEditingRangeRequest, Location, NotificationType0, ParameterInformation, Position, ProgressToken, ProtocolRequestType, Range, ReferencesRequest, RenameRequest, SelectionRange, SelectionRangeRequest, SemanticTokensRegistrationType, SignatureHelpRequest, SignatureHelpTriggerKind, SignatureInformation, TextDocumentEdit, TextDocumentSyncKind, TextEdit, TypeDefinitionRequest, TypeHierarchyPrepareRequest, WillCreateFilesRequest, WillDeleteFilesRequest, WillRenameFilesRequest, WillSaveTextDocumentNotification, WillSaveTextDocumentWaitUntilRequest, WorkDoneProgressBegin, WorkDoneProgressCreateRequest, WorkDoneProgressEnd, WorkDoneProgressReport, WorkspaceEdit, WorkspaceSymbolRequest } from 'vscode-languageserver-protocol'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { URI } from 'vscode-uri'
import commands from '../../commands'
Expand Down Expand Up @@ -154,6 +154,7 @@ describe('Client integration', () => {
documentSelector: [{ language: '*' }]
},
selectionRangeProvider: true,
inlineCompletionProvider: true,
inlineValueProvider: {},
inlayHintProvider: {
resolveProvider: true
Expand Down Expand Up @@ -270,6 +271,7 @@ describe('Client integration', () => {
testFeature(SemanticTokensRegistrationType.method, 'document')
testFeature(LinkedEditingRangeRequest.method, 'document')
testFeature(TypeHierarchyPrepareRequest.method, 'document')
testFeature(InlineCompletionRequest.method, 'document')
testFeature(InlineValueRequest.method, 'document')
testFeature(InlayHintRequest.method, 'document')
testFeature(WorkspaceSymbolRequest.method, 'workspace')
Expand Down Expand Up @@ -1351,6 +1353,27 @@ describe('Client integration', () => {
}, true)
})

test('Inline Completions', async () => {
const provider = client.getFeature(InlineCompletionRequest.method)?.getProvider(document)
isDefined(provider)
const results = (await provider.provideInlineCompletionItems(document, position, { triggerKind: 1, selectedCompletionInfo: { range, text: 'text' } }, tokenSource.token)) as InlineCompletionItem[]

isArray(results, InlineCompletionItem, 1)

rangeEqual(results[0].range!, 1, 2, 3, 4)
assert.strictEqual(results[0].filterText!, 'te')
assert.strictEqual(results[0].insertText, 'text inline')

let middlewareCalled = false
middleware.provideInlineCompletionItems = (d, r, c, t, n) => {
middlewareCalled = true
return n(d, r, c, t)
}
await provider.provideInlineCompletionItems(document, position, { triggerKind: 1, selectedCompletionInfo: undefined }, tokenSource.token)
middleware.provideInlineCompletionItems = undefined
assert.strictEqual(middlewareCalled, true)
})

test('Workspace symbols', async () => {
const providers = client.getFeature(WorkspaceSymbolRequest.method).getProviders()
isDefined(providers)
Expand Down
Loading

0 comments on commit d8c5456

Please sign in to comment.