vscode-languageclient
Advanced tools
Comparing version 7.1.0-next.2 to 7.1.0-next.3
@@ -1,2 +0,2 @@ | ||
import { TextDocumentChangeEvent, TextDocument, Disposable, OutputChannel, FileSystemWatcher as VFileSystemWatcher, DiagnosticCollection, Diagnostic as VDiagnostic, Uri, ProviderResult, CancellationToken, Position as VPosition, Location as VLocation, Range as VRange, CompletionItem as VCompletionItem, CompletionList as VCompletionList, SignatureHelp as VSignatureHelp, SignatureHelpContext as VSignatureHelpContext, Definition as VDefinition, DefinitionLink as VDefinitionLink, DocumentHighlight as VDocumentHighlight, SymbolInformation as VSymbolInformation, CodeActionContext as VCodeActionContext, Command as VCommand, CodeLens as VCodeLens, FormattingOptions as VFormattingOptions, TextEdit as VTextEdit, WorkspaceEdit as VWorkspaceEdit, Hover as VHover, CodeAction as VCodeAction, DocumentSymbol as VDocumentSymbol, DocumentLink as VDocumentLink, TextDocumentWillSaveEvent, WorkspaceFolder as VWorkspaceFolder, CompletionContext as VCompletionContext, CompletionItemProvider, HoverProvider, SignatureHelpProvider, DefinitionProvider, ReferenceProvider, DocumentHighlightProvider, CodeActionProvider, DocumentSymbolProvider, DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider, OnTypeFormattingEditProvider, RenameProvider, DocumentLinkProvider, DocumentColorProvider, DeclarationProvider, FoldingRangeProvider, ImplementationProvider, SelectionRangeProvider, TypeDefinitionProvider, WorkspaceSymbolProvider, CallHierarchyProvider, FileWillCreateEvent, FileWillRenameEvent, FileWillDeleteEvent, FileCreateEvent, FileDeleteEvent, FileRenameEvent, LinkedEditingRangeProvider, Event as VEvent } from 'vscode'; | ||
import { TextDocumentChangeEvent, TextDocument, Disposable, OutputChannel, FileSystemWatcher as VFileSystemWatcher, DiagnosticCollection, Diagnostic as VDiagnostic, Uri, ProviderResult, CancellationToken, Position as VPosition, Location as VLocation, Range as VRange, CompletionItem as VCompletionItem, CompletionList as VCompletionList, SignatureHelp as VSignatureHelp, SignatureHelpContext as VSignatureHelpContext, Definition as VDefinition, DefinitionLink as VDefinitionLink, DocumentHighlight as VDocumentHighlight, SymbolInformation as VSymbolInformation, CodeActionContext as VCodeActionContext, Command as VCommand, CodeLens as VCodeLens, FormattingOptions as VFormattingOptions, TextEdit as VTextEdit, WorkspaceEdit as VWorkspaceEdit, Hover as VHover, CodeAction as VCodeAction, DocumentSymbol as VDocumentSymbol, DocumentLink as VDocumentLink, TextDocumentWillSaveEvent, WorkspaceFolder as VWorkspaceFolder, CompletionContext as VCompletionContext, CompletionItemProvider, HoverProvider, SignatureHelpProvider, DefinitionProvider, ReferenceProvider, DocumentHighlightProvider, CodeActionProvider, DocumentSymbolProvider, DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider, OnTypeFormattingEditProvider, RenameProvider, DocumentLinkProvider, DocumentColorProvider, DeclarationProvider, FoldingRangeProvider, ImplementationProvider, SelectionRangeProvider, TypeDefinitionProvider, WorkspaceSymbolProvider, CallHierarchyProvider, FileWillCreateEvent, FileWillRenameEvent, FileWillDeleteEvent, FileCreateEvent, FileDeleteEvent, FileRenameEvent, LinkedEditingRangeProvider, Event as VEvent, CancellationError } from 'vscode'; | ||
import { Message, MessageSignature, ResponseError, RequestType0, RequestType, NotificationType0, NotificationType, ProtocolRequestType, ProtocolRequestType0, RequestHandler, RequestHandler0, GenericRequestHandler, ProtocolNotificationType, ProtocolNotificationType0, NotificationHandler, NotificationHandler0, GenericNotificationHandler, MessageReader, MessageWriter, Trace, Event, ClientCapabilities, TextDocumentRegistrationOptions, InitializeParams, InitializeResult, InitializeError, ServerCapabilities, DocumentSelector, DidOpenTextDocumentNotification, DidOpenTextDocumentParams, DidChangeTextDocumentNotification, DidChangeTextDocumentParams, DidCloseTextDocumentNotification, DidCloseTextDocumentParams, DidSaveTextDocumentNotification, DidSaveTextDocumentParams, WillSaveTextDocumentNotification, WillSaveTextDocumentWaitUntilRequest, FileEvent, CompletionRequest, HoverRequest, SignatureHelpRequest, DefinitionRequest, ReferencesRequest, DocumentHighlightRequest, DocumentSymbolRequest, WorkspaceSymbolRequest, CodeActionRequest, DocumentFormattingRequest, DocumentRangeFormattingRequest, DocumentOnTypeFormattingRequest, RenameRequest, DocumentLinkRequest, ProgressType, ProgressToken, StaticRegistrationOptions, DocumentColorRequest, DeclarationRequest, FoldingRangeRequest, ImplementationRequest, SelectionRangeRequest, TypeDefinitionRequest, CallHierarchyPrepareRequest, CancellationStrategy, RegistrationType, SemanticTokensRegistrationType, ShowDocumentRequest, FileOperationRegistrationOptions, WillCreateFilesRequest, WillRenameFilesRequest, WillDeleteFilesRequest, DidCreateFilesNotification, DidDeleteFilesNotification, DidRenameFilesNotification, ShowDocumentParams, ShowDocumentResult, LinkedEditingRangeRequest, WorkDoneProgressBegin, WorkDoneProgressEnd, WorkDoneProgressReport } from 'vscode-languageserver-protocol'; | ||
@@ -426,2 +426,6 @@ import type { ColorProviderMiddleware } from './colorProvider'; | ||
} | ||
export declare class LSPCancellationError extends CancellationError { | ||
readonly data: object | Object; | ||
constructor(data: object | Object); | ||
} | ||
export declare abstract class BaseLanguageClient { | ||
@@ -428,0 +432,0 @@ private _id; |
import { Disposable, CancellationToken, ProviderResult, Diagnostic as VDiagnostic, TextDocument } from 'vscode'; | ||
import { Proposed, ClientCapabilities, ServerCapabilities, DocumentSelector } from 'vscode-languageserver-protocol'; | ||
import { TextDocumentFeature, BaseLanguageClient } from './client'; | ||
interface VDiagnosticList { | ||
items: VDiagnostic[]; | ||
} | ||
interface DiagnosticProvider { | ||
provideDiagnostics(textDocument: TextDocument, token: CancellationToken): ProviderResult<VDiagnostic[]>; | ||
provideDiagnostics(textDocument: TextDocument, context: Proposed.DiagnosticContext, token: CancellationToken): ProviderResult<VDiagnosticList>; | ||
} | ||
export interface ProvideDiagnosticSignature { | ||
(this: void, textDocument: TextDocument, token: CancellationToken): ProviderResult<VDiagnostic[]>; | ||
(this: void, textDocument: TextDocument, context: Proposed.DiagnosticContext, token: CancellationToken): ProviderResult<VDiagnosticList>; | ||
} | ||
export interface DiagnosticProviderMiddleware { | ||
provideDiagnostics?: (this: void, document: TextDocument, token: CancellationToken, next: ProvideDiagnosticSignature) => ProviderResult<VDiagnostic[]>; | ||
provideDiagnostics?: (this: void, document: TextDocument, context: Proposed.DiagnosticContext, token: CancellationToken, next: ProvideDiagnosticSignature) => ProviderResult<VDiagnosticList>; | ||
} | ||
export declare class DiagnosticFeature extends TextDocumentFeature<Proposed.DiagnosticOptions, Proposed.DiagnosticRegistrationOptions, DiagnosticProvider> { | ||
export declare class DiagnosticFeature extends TextDocumentFeature<boolean | Proposed.DiagnosticOptions, Proposed.DiagnosticRegistrationOptions, DiagnosticProvider> { | ||
private readonly openFeature; | ||
@@ -15,0 +18,0 @@ private readonly changeFeature; |
@@ -44,3 +44,3 @@ "use strict"; | ||
const documentSelector = options.documentSelector; | ||
const mode = vscode_languageserver_protocol_1.Proposed.DiagnosticPullMode.is(options.mode) ? options.mode : vscode_languageserver_protocol_1.Proposed.DiagnosticPullMode.onType; | ||
const mode = vscode_languageserver_protocol_1.Proposed.DiagnosticPullModeFlags.is(options.mode) ? options.mode : (vscode_languageserver_protocol_1.Proposed.DiagnosticPullModeFlags.onOpen | vscode_languageserver_protocol_1.Proposed.DiagnosticPullModeFlags.onType); | ||
const disposables = []; | ||
@@ -58,15 +58,16 @@ const collection = vscode_1.languages.createDiagnosticCollection(options.identifier); | ||
const provider = { | ||
provideDiagnostics: (textDocument, token) => { | ||
provideDiagnostics: (textDocument, context, token) => { | ||
const client = this._client; | ||
const provideDiagnostics = (textDocument, token) => { | ||
const provideDiagnostics = (textDocument, context, token) => { | ||
const params = { | ||
textDocument: { uri: client.code2ProtocolConverter.asUri(textDocument.uri) } | ||
textDocument: { uri: client.code2ProtocolConverter.asUri(textDocument.uri) }, | ||
context: context | ||
}; | ||
return client.sendRequest(vscode_languageserver_protocol_1.Proposed.DiagnosticRequest.type, params, token).then((result) => { | ||
if (result === null) { | ||
return []; | ||
if (result === null || !result.items) { | ||
return { items: [] }; | ||
} | ||
return client.protocol2CodeConverter.asDiagnostics(result); | ||
return { items: client.protocol2CodeConverter.asDiagnostics(result.items) }; | ||
}, (error) => { | ||
return client.handleFailedRequest(vscode_languageserver_protocol_1.Proposed.DiagnosticRequest.type, token, error, []); | ||
return client.handleFailedRequest(vscode_languageserver_protocol_1.Proposed.DiagnosticRequest.type, token, error, { items: [] }); | ||
}); | ||
@@ -76,8 +77,8 @@ }; | ||
return middleware.provideDiagnostics | ||
? middleware.provideDiagnostics(textDocument, token, provideDiagnostics) | ||
: provideDiagnostics(textDocument, token); | ||
? middleware.provideDiagnostics(textDocument, context, token, provideDiagnostics) | ||
: provideDiagnostics(textDocument, context, token); | ||
} | ||
}; | ||
const requestStates = new Map(); | ||
const pullDiagnostics = async (textDocument) => { | ||
const pullDiagnostics = async (textDocument, trigger) => { | ||
var _a; | ||
@@ -89,4 +90,4 @@ const key = textDocument.uri.toString(); | ||
currentState.tokenSource.cancel(); | ||
requestStates.set(key, { state: RequestStateKind.reschedule, textDocument }); | ||
} | ||
requestStates.set(key, { state: RequestStateKind.reschedule, textDocument, trigger: trigger }); | ||
// We have a state. Wait until the request returns. | ||
@@ -96,5 +97,20 @@ return; | ||
const tokenSource = new vscode_1.CancellationTokenSource(); | ||
requestStates.set(key, { state: RequestStateKind.active, textDocument, tokenSource }); | ||
const diagnostics = (_a = await provider.provideDiagnostics(textDocument, tokenSource.token)) !== null && _a !== void 0 ? _a : []; | ||
const afterState = requestStates.get(key); | ||
requestStates.set(key, { state: RequestStateKind.active, textDocument, trigger, tokenSource }); | ||
let diagnostics; | ||
let afterState; | ||
try { | ||
diagnostics = (_a = await provider.provideDiagnostics(textDocument, { triggerKind: trigger }, tokenSource.token)) !== null && _a !== void 0 ? _a : { items: [] }; | ||
} | ||
catch (error) { | ||
if (error instanceof client_1.LSPCancellationError && vscode_languageserver_protocol_1.Proposed.DiagnosticServerCancellationData.is(error.data) && error.data.retriggerRequest === false) { | ||
afterState = { state: RequestStateKind.outDated, textDocument }; | ||
} | ||
if (afterState === undefined && error instanceof vscode_1.CancellationError) { | ||
afterState = { state: RequestStateKind.reschedule, textDocument, trigger }; | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
afterState = afterState !== null && afterState !== void 0 ? afterState : requestStates.get(key); | ||
if (afterState === undefined) { | ||
@@ -107,8 +123,11 @@ // This shouldn't happen. Log it | ||
requestStates.delete(key); | ||
if (afterState.state === RequestStateKind.outDated) { | ||
if (afterState.state === RequestStateKind.outDated || !manages(textDocument)) { | ||
return; | ||
} | ||
collection.set(textDocument.uri, diagnostics); | ||
// diagnostics is only undefined if the request has thrown. | ||
if (diagnostics !== undefined) { | ||
collection.set(textDocument.uri, diagnostics.items); | ||
} | ||
if (afterState.state === RequestStateKind.reschedule) { | ||
pullDiagnostics(textDocument); | ||
pullDiagnostics(textDocument, afterState.trigger); | ||
} | ||
@@ -124,29 +143,31 @@ }; | ||
disposables.push(vscode_1.window.onDidChangeOpenEditors(openEditorsHandler)); | ||
disposables.push(this.openFeature.onNotificationSent((event) => { | ||
const textDocument = event.original; | ||
if (matches(textDocument)) { | ||
managedDocuments.add(textDocument.uri.toString()); | ||
pullDiagnostics(event.original); | ||
if (vscode_languageserver_protocol_1.Proposed.DiagnosticPullModeFlags.isOpen(mode)) { | ||
disposables.push(this.openFeature.onNotificationSent((event) => { | ||
const textDocument = event.original; | ||
if (matches(textDocument)) { | ||
managedDocuments.add(textDocument.uri.toString()); | ||
pullDiagnostics(event.original, vscode_languageserver_protocol_1.Proposed.DiagnosticTriggerKind.Opened); | ||
} | ||
})); | ||
// Pull all diagnostics for documents that are already open | ||
for (const textDocument of this.openFeature.openDocuments) { | ||
if (matches(textDocument)) { | ||
managedDocuments.add(textDocument.uri.toString()); | ||
pullDiagnostics(textDocument, vscode_languageserver_protocol_1.Proposed.DiagnosticTriggerKind.Opened); | ||
} | ||
} | ||
})); | ||
// Pull all diagnostics for documents that are already open | ||
for (const textDocument of this.openFeature.openDocuments) { | ||
if (matches(textDocument)) { | ||
managedDocuments.add(textDocument.uri.toString()); | ||
pullDiagnostics(textDocument); | ||
} | ||
} | ||
if (mode === vscode_languageserver_protocol_1.Proposed.DiagnosticPullMode.onType) { | ||
if (vscode_languageserver_protocol_1.Proposed.DiagnosticPullModeFlags.isType(mode)) { | ||
disposables.push(this.changeFeature.onNotificationSent((event) => { | ||
const textDocument = event.original.document; | ||
if (manages(textDocument) && event.original.contentChanges.length > 0) { | ||
pullDiagnostics(textDocument); | ||
pullDiagnostics(textDocument, vscode_languageserver_protocol_1.Proposed.DiagnosticTriggerKind.Typed); | ||
} | ||
})); | ||
} | ||
else if (mode === vscode_languageserver_protocol_1.Proposed.DiagnosticPullMode.onSave) { | ||
if (vscode_languageserver_protocol_1.Proposed.DiagnosticPullModeFlags.isSave(mode)) { | ||
disposables.push(this.saveFeature.onNotificationSent((event) => { | ||
const textDocument = event.original; | ||
if (manages(textDocument)) { | ||
pullDiagnostics(event.original); | ||
pullDiagnostics(event.original, vscode_languageserver_protocol_1.Proposed.DiagnosticTriggerKind.Saved); | ||
} | ||
@@ -157,2 +178,6 @@ })); | ||
const textDocument = event.original; | ||
const requestState = requestStates.get(textDocument.uri.toString()); | ||
if (requestState !== undefined) { | ||
requestStates.set(textDocument.uri.toString(), { state: RequestStateKind.outDated, textDocument }); | ||
} | ||
if (manages(textDocument)) { | ||
@@ -159,0 +184,0 @@ collection.delete(textDocument.uri); |
{ | ||
"name": "vscode-languageclient", | ||
"description": "VSCode Language client implementation", | ||
"version": "7.1.0-next.2", | ||
"version": "7.1.0-next.3", | ||
"author": "Microsoft Corporation", | ||
@@ -32,3 +32,3 @@ "license": "MIT", | ||
"semver": "^7.3.4", | ||
"vscode-languageserver-protocol": "3.17.0-next.3" | ||
"vscode-languageserver-protocol": "3.17.0-next.4" | ||
}, | ||
@@ -35,0 +35,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
410183
8306
+ Addedvscode-jsonrpc@6.1.0-next.2(transitive)
+ Addedvscode-languageserver-protocol@3.17.0-next.4(transitive)
- Removedvscode-jsonrpc@6.1.0-next.1(transitive)
- Removedvscode-languageserver-protocol@3.17.0-next.3(transitive)