Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
51 changes: 12 additions & 39 deletions src/client/activation/common/activatorBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
SignatureHelpContext,
SymbolInformation,
TextDocument,
TextDocumentContentChangeEvent,
WorkspaceEdit
} from 'vscode';
import * as vscodeLanguageClient from 'vscode-languageclient/node';
Expand Down Expand Up @@ -72,34 +71,25 @@ export abstract class LanguageServerActivatorBase implements ILanguageServerActi
this.manager.disconnect();
}

public handleOpen(document: TextDocument): void {
public get connection() {
const languageClient = this.getLanguageClient();
if (languageClient) {
languageClient.sendNotification(
vscodeLanguageClient.DidOpenTextDocumentNotification.type,
languageClient.code2ProtocolConverter.asOpenTextDocumentParams(document)
);
// Return an object that looks like a connection
return {
sendNotification: languageClient.sendNotification.bind(languageClient),
sendRequest: languageClient.sendRequest.bind(languageClient),
sendProgress: languageClient.sendProgress.bind(languageClient),
onRequest: languageClient.onRequest.bind(languageClient),
onNotification: languageClient.onNotification.bind(languageClient),
onProgress: languageClient.onProgress.bind(languageClient)
};
}
}

public handleChanges(document: TextDocument, changes: TextDocumentContentChangeEvent[]): void {
public get capabilities() {
const languageClient = this.getLanguageClient();
if (languageClient) {
// If the language client doesn't support incremental, just send the whole document
if (this.textDocumentSyncKind === vscodeLanguageClient.TextDocumentSyncKind.Full) {
languageClient.sendNotification(
vscodeLanguageClient.DidChangeTextDocumentNotification.type,
languageClient.code2ProtocolConverter.asChangeTextDocumentParams(document)
);
} else {
languageClient.sendNotification(
vscodeLanguageClient.DidChangeTextDocumentNotification.type,
languageClient.code2ProtocolConverter.asChangeTextDocumentParams({
document,
contentChanges: changes
})
);
}
return languageClient.initializeResult?.capabilities;
}
}

Expand Down Expand Up @@ -169,23 +159,6 @@ export abstract class LanguageServerActivatorBase implements ILanguageServerActi
}
}

private get textDocumentSyncKind(): vscodeLanguageClient.TextDocumentSyncKind {
const languageClient = this.getLanguageClient();
if (languageClient?.initializeResult?.capabilities?.textDocumentSync) {
const syncOptions = languageClient.initializeResult.capabilities.textDocumentSync;
const syncKind =
syncOptions !== undefined && syncOptions.hasOwnProperty('change')
? (syncOptions as vscodeLanguageClient.TextDocumentSyncOptions).change
: syncOptions;
if (syncKind !== undefined) {
return syncKind as vscodeLanguageClient.TextDocumentSyncKind;
}
}

// Default is full if not provided
return vscodeLanguageClient.TextDocumentSyncKind.Full;
}

private async handleProvideRenameEdits(
document: TextDocument,
position: Position,
Expand Down
15 changes: 7 additions & 8 deletions src/client/activation/jedi/multiplexingActivator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
Position,
ReferenceContext,
SignatureHelpContext,
TextDocument,
TextDocumentContentChangeEvent
TextDocument
} from 'vscode';
// tslint:disable-next-line: import-name
import { IWorkspaceService } from '../../common/application/types';
Expand Down Expand Up @@ -73,15 +72,15 @@ export class MultiplexingJediLanguageServerActivator implements ILanguageServerA
return this.onDidChangeCodeLensesEmitter.event;
}

public handleChanges(document: TextDocument, changes: TextDocumentContentChangeEvent[]) {
if (this.realLanguageServer && this.realLanguageServer.handleChanges) {
this.realLanguageServer.handleChanges(document, changes);
public get connection() {
if (this.realLanguageServer) {
return this.realLanguageServer.connection;
}
}

public handleOpen(document: TextDocument) {
if (this.realLanguageServer && this.realLanguageServer.handleOpen) {
this.realLanguageServer.handleOpen(document);
public get capabilities() {
if (this.realLanguageServer) {
return this.realLanguageServer.capabilities;
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/client/activation/refCountedLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
SignatureHelpContext,
SymbolInformation,
TextDocument,
TextDocumentContentChangeEvent,
WorkspaceEdit
} from 'vscode';

Expand Down Expand Up @@ -65,12 +64,12 @@ export class RefCountedLanguageServer implements ILanguageServerActivator {
this.impl.clearAnalysisCache ? this.impl.clearAnalysisCache() : noop();
}

public handleChanges(document: TextDocument, changes: TextDocumentContentChangeEvent[]) {
this.impl.handleChanges ? this.impl.handleChanges(document, changes) : noop();
public get connection() {
return this.impl.connection;
}

public handleOpen(document: TextDocument) {
this.impl.handleOpen ? this.impl.handleOpen(document) : noop();
public get capabilities() {
return this.impl.capabilities;
}

public provideRenameEdits(
Expand Down
18 changes: 7 additions & 11 deletions src/client/activation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {
HoverProvider,
ReferenceProvider,
RenameProvider,
SignatureHelpProvider,
TextDocument,
TextDocumentContentChangeEvent
SignatureHelpProvider
} from 'vscode';
import { LanguageClient, LanguageClientOptions } from 'vscode-languageclient/node';
import * as vscodeprotocol from 'vscode-languageserver-protocol';
Comment thread
rchiodo marked this conversation as resolved.
Resolved
import { NugetPackage } from '../common/nuget/types';
import { IDisposable, IOutputChannel, LanguageServerDownloadChannels, Resource } from '../common/types';
import { ILanguageServerConnection } from '../datascience/api/jupyterIntegration';
Comment thread
jakebailey marked this conversation as resolved.
Resolved
import { PythonEnvironment } from '../pythonEnvironments/info';

export const IExtensionActivationManager = Symbol('IExtensionActivationManager');
Expand Down Expand Up @@ -73,12 +73,6 @@ export enum LanguageServerType {
export const DotNetLanguageServerFolder = 'languageServer';
export const NodeLanguageServerFolder = 'nodeLanguageServer';

// tslint:disable-next-line: interface-name
export interface DocumentHandler {
handleOpen(document: TextDocument): void;
handleChanges(document: TextDocument, changes: TextDocumentContentChangeEvent[]): void;
}

// tslint:disable-next-line: interface-name
export interface LanguageServerCommandHandler {
clearAnalysisCache(): void;
Expand All @@ -93,9 +87,11 @@ export interface ILanguageServer
CodeLensProvider,
DocumentSymbolProvider,
SignatureHelpProvider,
Partial<DocumentHandler>,
Partial<LanguageServerCommandHandler>,
IDisposable {}
IDisposable {
readonly connection?: ILanguageServerConnection;
readonly capabilities?: vscodeprotocol.ServerCapabilities;
}

export const ILanguageServerActivator = Symbol('ILanguageServerActivator');
export interface ILanguageServerActivator extends ILanguageServer {
Expand Down
Loading