Skip to content
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
14 changes: 4 additions & 10 deletions src/fileEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import * as stringInterpolate from 'fmtr';
import { apiManager } from './apiManager';

let serverReady: boolean = false;
type LanguageClientProvider = LanguageClient | (() => LanguageClient);

const BRACE_POSITION_KEY = "org.eclipse.jdt.core.formatter.brace_position_for_type_declaration";
const END_OF_LINE = "end_of_line";
Expand All @@ -25,7 +24,7 @@ export function setServerStatus(ready: boolean) {
serverReady = ready;
}

export function registerFileEventHandlers(client: LanguageClientProvider, context: ExtensionContext) {
export function registerFileEventHandlers(client: LanguageClient, context: ExtensionContext) {
if (workspace.onDidCreateFiles) {// Theia doesn't support workspace.onDidCreateFiles yet
context.subscriptions.push(workspace.onDidCreateFiles(handleNewJavaFiles));
}
Expand Down Expand Up @@ -191,11 +190,7 @@ async function handleNewJavaFiles(e: FileCreateEvent) {
}, 100);
}

function getLanguageClient(client: LanguageClientProvider): LanguageClient {
return typeof client === 'function' ? client() : client;
}

function getWillRenameHandler(client: LanguageClientProvider) {
function getWillRenameHandler(client: LanguageClient) {
return function handleWillRenameFiles(e: FileWillRenameEvent): void {
if (!serverReady) {
return;
Expand All @@ -220,11 +215,10 @@ function getWillRenameHandler(client: LanguageClientProvider) {
return;
}

const languageClient = getLanguageClient(client);
const edit = await languageClient.sendRequest(WillRenameFiles.type, {
const edit = await client.sendRequest(WillRenameFiles.type, {
files: javaRenameEvents
});
resolve(await languageClient.protocol2CodeConverter.asWorkspaceEdit(edit));
resolve(await client.protocol2CodeConverter.asWorkspaceEdit(edit));
} catch (ex) {
reject(ex);
}
Expand Down
32 changes: 6 additions & 26 deletions src/standardLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as net from 'net';
import * as path from 'path';
import { CancellationToken, CodeActionKind, commands, ConfigurationTarget, DocumentSelector, EventEmitter, ExtensionContext, extensions, languages, Location, ProgressLocation, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceConfiguration } from "vscode";
import { ConfigurationParams, ConfigurationRequest, LanguageClientOptions, Location as LSLocation, MessageType, Position as LSPosition, TextDocumentPositionParams, WorkspaceEdit, StaticFeature, ClientCapabilities, FeatureState, TelemetryEventNotification } from "vscode-languageclient";
import { LanguageClient, ServerOptions, StreamInfo } from "vscode-languageclient/node";
import { LanguageClient, StreamInfo } from "vscode-languageclient/node";
import { apiManager } from "./apiManager";
import * as buildPath from './buildpath';
import { javaRefactorKinds, RefactorDocumentProvider } from "./codeActionProvider";
Expand Down Expand Up @@ -42,7 +42,6 @@ import { listJdks, sortJdksBySource, sortJdksByVersion } from './jdkUtils';
import { ClientCodeActionProvider } from './clientCodeActionProvider';
import { BuildFileSelector } from './buildFilesSelector';
import { extendedOutlineQuickPick } from "./outline/extendedOutlineQuickPick";
import { startWithStdioFallback } from './standardLanguageClientStart';

const extensionName = 'Language Support for Java';
const GRADLE_CHECKSUM = "gradle/checksum/prompt";
Expand All @@ -51,7 +50,6 @@ const USE_JAVA = "Use Java ";
const AS_GRADLE_JVM = " as Gradle JVM";
const UPGRADE_GRADLE = "Upgrade Gradle to ";
const GRADLE_IMPORT_JVM = "java.import.gradle.java.home";
const PIPE_START_TIMEOUT_MS = 30000;
export const JAVA_SELECTOR: DocumentSelector = [
{ scheme: "file", language: "java", pattern: "**/*.java" },
{ scheme: "jdt", language: "java", pattern: "**/*.class" },
Expand All @@ -61,8 +59,6 @@ export const JAVA_SELECTOR: DocumentSelector = [
export class StandardLanguageClient {

private languageClient: LanguageClient;
private serverOptions: ServerOptions;
private clientOptions: LanguageClientOptions;
private status: ClientStatus = ClientStatus.uninitialized;

public async initialize(context: ExtensionContext, requirements: RequirementsData, clientOptions: LanguageClientOptions, workspacePath: string, jdtEventEmitter: EventEmitter<Uri>): Promise<void> {
Expand All @@ -89,7 +85,7 @@ export class StandardLanguageClient {
}
});

let serverOptions: ServerOptions;
let serverOptions;
const port = process.env['JDTLS_SERVER_PORT'];
if (!port) {
const lsPort = process.env['JDTLS_CLIENT_PORT'];
Expand All @@ -109,26 +105,19 @@ export class StandardLanguageClient {
// used during development
serverOptions = awaitServerConnection.bind(null, port);
}
this.serverOptions = serverOptions;
this.clientOptions = clientOptions;

// Create the language client and start the client.
this.languageClient = this.createLanguageClient(serverOptions, clientOptions);
this.languageClient = new TracingLanguageClient('java', extensionName, serverOptions, clientOptions, DEBUG);
this.languageClient.registerFeature(new DisableWillRenameFeature());

this.registerCommandsForStandardServer(context, jdtEventEmitter);
fileEventHandler.registerFileEventHandlers(() => this.languageClient, context);
fileEventHandler.registerFileEventHandlers(this.languageClient, context);

collectBuildFilePattern(extensions.all);

this.status = ClientStatus.initialized;
}

private createLanguageClient(serverOptions: ServerOptions, clientOptions: LanguageClientOptions): LanguageClient {
const languageClient = new TracingLanguageClient('java', extensionName, serverOptions, clientOptions, DEBUG);
languageClient.registerFeature(new DisableWillRenameFeature());
return languageClient;
}

public registerLanguageClientActions(context: ExtensionContext, hasImported: boolean, jdtEventEmitter: EventEmitter<Uri>) {
activationProgressNotification.showProgress();
this.languageClient.onNotification(StatusNotification.type, async (report) => {
Expand Down Expand Up @@ -788,16 +777,7 @@ export class StandardLanguageClient {
public start(): Promise<void> {
if (this.languageClient && this.status === ClientStatus.initialized) {
this.status = ClientStatus.starting;
return startWithStdioFallback({
languageClient: this.languageClient,
serverOptions: this.serverOptions,
createLanguageClient: (serverOptions) => this.createLanguageClient(serverOptions, this.clientOptions),
pipeStartTimeout: PIPE_START_TIMEOUT_MS,
onFallback: (error) => logger.warn(`Falling back to 'stdio' (from 'pipe') because starting the pipe transport failed: ${error}`),
}).then(result => {
this.languageClient = result.client;
this.serverOptions = result.serverOptions;
});
return this.languageClient.start();
}
}

Expand Down
66 changes: 0 additions & 66 deletions src/standardLanguageClientStart.ts

This file was deleted.

83 changes: 0 additions & 83 deletions test/standard-mode-suite/standardLanguageClient.test.ts

This file was deleted.

Loading