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

Add more logging for ENOENT error #87

Closed
wants to merge 3 commits into from
Closed
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
90 changes: 51 additions & 39 deletions src/common/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as proc from 'child_process';
import * as fsapi from 'fs-extra';
import { Disposable, env, l10n, LanguageStatusSeverity, LogOutputChannel, WorkspaceFolder } from 'vscode';
import { State } from 'vscode-languageclient';
Expand Down Expand Up @@ -46,31 +47,42 @@ async function createServer(
// Set notification type
newEnv.LS_SHOW_NOTIFICATION = settings.showNotifications;

newEnv.PYTHONUTF8 = '1';

const args =
newEnv.USE_DEBUGPY === 'False' || !isDebugScript
? settings.interpreter.slice(1).concat([SERVER_SCRIPT_PATH])
: settings.interpreter.slice(1).concat([DEBUG_SERVER_SCRIPT_PATH]);
traceInfo(`Server run command: ${[command, ...args].join(' ')}`);

const serverOptions: ServerOptions = {
command,
args,
options: { cwd, env: newEnv },
};
if (fsapi.existsSync(command)) {
traceInfo(`Server executable exists: "${command}"`);
} else {
traceError(`Server executable does not exist: "${command}"`);
}

if (fsapi.existsSync(SERVER_SCRIPT_PATH)) {
traceInfo(`Server executable exists: "${SERVER_SCRIPT_PATH}"`);
} else {
traceError(`Server executable does not exist: "${SERVER_SCRIPT_PATH}"`);
}

// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Register the server for python documents
documentSelector: getDocumentSelector(),
outputChannel: outputChannel,
traceOutputChannel: outputChannel,
revealOutputChannelOn: RevealOutputChannelOn.Never,
initializationOptions,
};
try {
const serverOptions: ServerOptions = () =>
Promise.resolve(proc.spawn(command, args, { cwd, env: newEnv, stdio: ['pipe', 'pipe', 'pipe'] }));

return new LanguageClient(serverId, serverName, serverOptions, clientOptions);
// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Register the server for python documents
documentSelector: getDocumentSelector(),
outputChannel: outputChannel,
traceOutputChannel: outputChannel,
revealOutputChannelOn: RevealOutputChannelOn.Never,
initializationOptions,
};
return new LanguageClient(serverId, serverName, serverOptions, clientOptions);
} catch (err) {
traceError(`Error starting server: ${err}`);
throw err;
}
}

let _disposables: Disposable[] = [];
Expand All @@ -93,33 +105,33 @@ export async function restartServer(
}
updateStatus(undefined, LanguageStatusSeverity.Information, true);

const newLSClient = await createServer(workspaceSetting, serverId, serverName, outputChannel, {
settings: await getExtensionSettings(serverId, true),
globalSettings: await getGlobalSettings(serverId, false),
});
traceInfo(`Server: Start requested.`);
_disposables.push(
newLSClient.onDidChangeState((e) => {
switch (e.newState) {
case State.Stopped:
traceVerbose(`Server State: Stopped`);
break;
case State.Starting:
traceVerbose(`Server State: Starting`);
break;
case State.Running:
traceVerbose(`Server State: Running`);
updateStatus(undefined, LanguageStatusSeverity.Information, false);
break;
}
}),
);
try {
const newLSClient = await createServer(workspaceSetting, serverId, serverName, outputChannel, {
settings: await getExtensionSettings(serverId, true),
globalSettings: await getGlobalSettings(serverId, false),
});
traceInfo(`Server: Start requested.`);
_disposables.push(
newLSClient.onDidChangeState((e) => {
switch (e.newState) {
case State.Stopped:
traceVerbose(`Server State: Stopped`);
break;
case State.Starting:
traceVerbose(`Server State: Starting`);
break;
case State.Running:
traceVerbose(`Server State: Running`);
updateStatus(undefined, LanguageStatusSeverity.Information, false);
break;
}
}),
);
await newLSClient.start();
await newLSClient.setTrace(getLSClientTraceLevel(outputChannel.logLevel, env.logLevel));
return newLSClient;
} catch (ex) {
updateStatus(l10n.t('Server failed to start.'), LanguageStatusSeverity.Error);
traceError(`Server: Start failed: ${ex}`);
}
return newLSClient;
}