Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various issues #309

Merged
merged 5 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 36 additions & 30 deletions client/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
RequestType, RequestType0, RequestHandler, RequestHandler0, GenericRequestHandler,
NotificationType, NotificationType0,
NotificationHandler, NotificationHandler0, GenericNotificationHandler,
Trace, Tracer, CancellationToken, MessageConnection, MessageSignature, Disposable
Trace, Tracer, CancellationToken, MessageConnection, MessageSignature, Disposable, ProgressType
} from 'vscode-jsonrpc';

import {
Expand Down Expand Up @@ -41,43 +41,46 @@ export interface IConnection {
sendRequest<R>(method: string, param: any, token?: CancellationToken): Thenable<R>;
sendRequest<R>(type: string | MessageSignature, ...params: any[]): Thenable<R>;

onRequest<R, E>(type: RequestType0<R, E>, handler: RequestHandler0<R, E>): void;
onRequest<P, R, E>(type: RequestType<P, R, E>, handler: RequestHandler<P, R, E>): void;
onRequest<R, E>(method: string, handler: GenericRequestHandler<R, E>): void;
onRequest<R, E>(method: string | MessageSignature, handler: GenericRequestHandler<R, E>): void;
onRequest<R, E>(type: RequestType0<R, E>, handler: RequestHandler0<R, E>): Disposable;
onRequest<P, R, E>(type: RequestType<P, R, E>, handler: RequestHandler<P, R, E>): Disposable;
onRequest<R, E>(method: string, handler: GenericRequestHandler<R, E>): Disposable;
onRequest<R, E>(method: string | MessageSignature, handler: GenericRequestHandler<R, E>): Disposable;

sendNotification<RO>(type: NotificationType0): void;
sendNotification<P>(type: NotificationType<P>, params?: P): void;
sendNotification(method: string): void;
sendNotification(method: string, params: any): void;
sendNotification(method: string | MessageSignature, params?: any): void;
sendNotification(type: NotificationType0): Thenable<void>;
sendNotification<P>(type: NotificationType<P>, params?: P): Thenable<void>;
sendNotification(method: string): Thenable<void>;
sendNotification(method: string, params: any): Thenable<void>;
sendNotification(method: string | MessageSignature, params?: any): Thenable<void>;

onNotification<RO>(type: NotificationType0, handler: NotificationHandler0): void;
onNotification<P>(type: NotificationType<P>, handler: NotificationHandler<P>): void;
onNotification(method: string, handler: GenericNotificationHandler): void;
onNotification(method: string | MessageSignature, handler: GenericNotificationHandler): void;
onNotification(type: NotificationType0, handler: NotificationHandler0): Disposable;
onNotification<P>(type: NotificationType<P>, handler: NotificationHandler<P>): Disposable;
onNotification(method: string, handler: GenericNotificationHandler): Disposable;
onNotification(method: string | MessageSignature, handler: GenericNotificationHandler): Disposable;

onProgress<P>(type: ProgressType<P>, token: string | number, handler: NotificationHandler<P>): Disposable;
sendProgress<P>(type: ProgressType<P>, token: string | number, value: P): Thenable<void>;

trace(value: Trace, tracer: Tracer, sendNotification?: boolean): void;

initialize(params: InitializeParams): Thenable<InitializeResult>;
shutdown(): Thenable<void>;
exit(): void;
exit(): Thenable<void>;

onLogMessage(handle: NotificationHandler<LogMessageParams>): void;
onShowMessage(handler: NotificationHandler<ShowMessageParams>): void;
onTelemetry(handler: NotificationHandler<any>): void;

didChangeConfiguration(params: DidChangeConfigurationParams): void;
didChangeWatchedFiles(params: DidChangeWatchedFilesParams): void;
didChangeConfiguration(params: DidChangeConfigurationParams): Thenable<void>;
didChangeWatchedFiles(params: DidChangeWatchedFilesParams): Thenable<void>;

didOpenTextDocument(params: DidOpenTextDocumentParams): void;
didChangeTextDocument(params: DidChangeTextDocumentParams): void;
didCloseTextDocument(params: DidCloseTextDocumentParams): void;
didSaveTextDocument(params: DidSaveTextDocumentParams): void;
didOpenTextDocument(params: DidOpenTextDocumentParams): Thenable<void>;
didChangeTextDocument(params: DidChangeTextDocumentParams): Thenable<void>;
didCloseTextDocument(params: DidCloseTextDocumentParams): Thenable<void>;
didSaveTextDocument(params: DidSaveTextDocumentParams): Thenable<void>;
onDiagnostics(handler: NotificationHandler<PublishDiagnosticsParams>): void;

end(): void;
dispose(): void;
end(): void
}

export interface ConnectionErrorHandler {
Expand All @@ -99,26 +102,29 @@ export function createConnection(connection: MessageConnection, errorHandler: Co
sendRequest: <R>(type: string | MessageSignature, ...params: any[]): Thenable<R> => connection.sendRequest(Is.string(type) ? type : type.method, ...params),
onRequest: <R, E>(type: string | MessageSignature, handler: GenericRequestHandler<R, E>): Disposable => connection.onRequest(Is.string(type) ? type : type.method, handler),

sendNotification: (type: string | MessageSignature, params?: any): void => connection.sendNotification(Is.string(type) ? type : type.method, params),
sendNotification: async (type: string | MessageSignature, params?: any): Promise<void> => connection.sendNotification(Is.string(type) ? type : type.method, params),
onNotification: (type: string | MessageSignature, handler: GenericNotificationHandler): Disposable => connection.onNotification(Is.string(type) ? type : type.method, handler),

onProgress: <P>(type: ProgressType<P>, token: string | number, handler: NotificationHandler<P>): Disposable => connection.onProgress(type, token, handler),
sendProgress: async <P>(type: ProgressType<P>, token: string | number, value: P) => connection.sendProgress(type, token, value),

trace: (value: Trace, tracer: Tracer, sendNotification: boolean = false): void => connection.trace(value, tracer, sendNotification),

initialize: (params: InitializeParams) => connection.sendRequest(InitializeRequest.type, params),
shutdown: () => connection.sendRequest(ShutdownRequest.type, undefined),
exit: () => connection.sendNotification(ExitNotification.type),
exit: async () => connection.sendNotification(ExitNotification.type),

onLogMessage: (handler: NotificationHandler<LogMessageParams>) => connection.onNotification(LogMessageNotification.type, handler),
onShowMessage: (handler: NotificationHandler<ShowMessageParams>) => connection.onNotification(ShowMessageNotification.type, handler),
onTelemetry: (handler: NotificationHandler<any>) => connection.onNotification(TelemetryEventNotification.type, handler),

didChangeConfiguration: (params: DidChangeConfigurationParams) => connection.sendNotification(DidChangeConfigurationNotification.type, params),
didChangeWatchedFiles: (params: DidChangeWatchedFilesParams) => connection.sendNotification(DidChangeWatchedFilesNotification.type, params),
didChangeConfiguration: async (params: DidChangeConfigurationParams) => connection.sendNotification(DidChangeConfigurationNotification.type, params),
didChangeWatchedFiles: async (params: DidChangeWatchedFilesParams) => connection.sendNotification(DidChangeWatchedFilesNotification.type, params),

didOpenTextDocument: (params: DidOpenTextDocumentParams) => connection.sendNotification(DidOpenTextDocumentNotification.type, params),
didChangeTextDocument: (params: DidChangeTextDocumentParams) => connection.sendNotification(DidChangeTextDocumentNotification.type, params),
didCloseTextDocument: (params: DidCloseTextDocumentParams) => connection.sendNotification(DidCloseTextDocumentNotification.type, params),
didSaveTextDocument: (params: DidSaveTextDocumentParams) => connection.sendNotification(DidSaveTextDocumentNotification.type, params),
didOpenTextDocument: async (params: DidOpenTextDocumentParams) => connection.sendNotification(DidOpenTextDocumentNotification.type, params),
didChangeTextDocument: async (params: DidChangeTextDocumentParams) => connection.sendNotification(DidChangeTextDocumentNotification.type, params),
didCloseTextDocument: async (params: DidCloseTextDocumentParams) => connection.sendNotification(DidCloseTextDocumentNotification.type, params),
didSaveTextDocument: async (params: DidSaveTextDocumentParams) => connection.sendNotification(DidSaveTextDocumentNotification.type, params),

onDiagnostics: (handler: NotificationHandler<PublishDiagnosticsParams>) => connection.onNotification(PublishDiagnosticsNotification.type, handler),

Expand Down
2 changes: 2 additions & 0 deletions client/src/monaco-language-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ColorProviderFeature } from "vscode-languageclient/lib/common/colorProv
import { WorkspaceFoldersFeature } from "vscode-languageclient/lib/common/workspaceFolders";
import { FoldingRangeFeature } from "vscode-languageclient/lib/common/foldingRange";
import { CallHierarchyFeature } from "vscode-languageclient/lib/common/callHierarchy";
import { ProgressFeature } from "vscode-languageclient/lib/common/progress";
import { SemanticTokensFeature } from "vscode-languageclient/lib/common/semanticTokens";
import * as p2c from 'vscode-languageclient/lib/common/protocolConverter';
import * as c2p from 'vscode-languageclient/lib/common/codeConverter';
Expand Down Expand Up @@ -98,6 +99,7 @@ export class MonacoLanguageClient extends BaseLanguageClient {
this.registerFeature(new DeclarationFeature(this));
this.registerFeature(new SemanticTokensFeature(this));
this.registerFeature(new CallHierarchyFeature(this));
this.registerFeature(new ProgressFeature(this));

const features = this['_features'] as ((StaticFeature | DynamicFeature<any>)[]);
for (const feature of features) {
Expand Down
4 changes: 4 additions & 0 deletions client/src/monaco-languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ export class MonacoLanguages implements Languages {
getLegend() {
return legend;
},
onDidChange: provider.onDidChange,
provideDocumentSemanticTokens: async (model, lastResultId, token) => {
if (!this.matchModel(selector, MonacoModelIdentifier.fromModel(model))) {
return undefined;
Expand Down Expand Up @@ -609,6 +610,9 @@ export class MonacoLanguages implements Languages {
} else {
languages.add(this.matchLanguageByFilter(selector));
}
if (languages.has('*')) {
return new Set(['*'])
}
return languages;
}

Expand Down
7 changes: 7 additions & 0 deletions client/src/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ export enum VsCodeDiagnosticSeverity {
Hint = 3
}

export enum ProgressLocation {
SourceControl = 1,
Window = 10,
Notification = 15
}

export interface SignatureHelpContext {
readonly triggerKind: SignatureHelpTriggerKind;
readonly triggerCharacter?: string;
Expand Down Expand Up @@ -200,6 +206,7 @@ export interface SelectionRangeProvider {
}

export interface DocumentSemanticTokensProvider {
onDidChange?: Event<void>;
provideDocumentSemanticTokens(params: SemanticTokensParams, token: CancellationToken): ProviderResult<SemanticTokens>;
provideDocumentSemanticTokensEdits?(params: SemanticTokensDeltaParams, token: CancellationToken): ProviderResult<SemanticTokens | SemanticTokensEdit>;
}
Expand Down
9 changes: 6 additions & 3 deletions client/src/vscode-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
MessageActionItem
} from "./services";
import * as ServicesModule from "./services";
import { DiagnosticSeverity } from "vscode-languageserver-protocol";
import { CancellationTokenSource, DiagnosticSeverity } from "vscode-languageserver-protocol";

export function createVSCodeApi(servicesProvider: Services.Provider): typeof vscode {
const unsupported = () => { throw new Error('unsupported') };
Expand Down Expand Up @@ -738,6 +738,7 @@ export function createVSCodeApi(servicesProvider: Services.Provider): typeof vsc
}

return languages.registerDocumentSemanticTokensProvider(selector, {
onDidChange: provider.onDidChangeSemanticTokens,
provideDocumentSemanticTokens({ textDocument }, token) {
return provider.provideDocumentSemanticTokens(<any>textDocument, token) as any;
},
Expand Down Expand Up @@ -811,7 +812,7 @@ export function createVSCodeApi(servicesProvider: Services.Provider): typeof vsc
if (window && window.withProgress) {
return window.withProgress(options, task);
}
return task({ report: () => { } }, new vscode.CancellationTokenSource().token);
return task({ report: () => { } }, new CancellationTokenSource().token);
},
showTextDocument: unsupported,
createTextEditorDecorationType: unsupported,
Expand Down Expand Up @@ -940,7 +941,9 @@ export function createVSCodeApi(servicesProvider: Services.Provider): typeof vsc
Disposable: CodeDisposable,
SignatureHelpTriggerKind: SignatureHelpTriggerKind,
DiagnosticSeverity: ServicesModule.DiagnosticSeverity,
EventEmitter: ServicesModule.Emitter
EventEmitter: ServicesModule.Emitter,
CancellationTokenSource,
ProgressLocation: ServicesModule.ProgressLocation
};

return partialApi as any;
Expand Down