Skip to content

Commit

Permalink
Sepatate start / stop server logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Jul 24, 2024
1 parent 382286f commit c21d41a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
18 changes: 9 additions & 9 deletions src/common/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,21 +396,14 @@ async function createServer(
}

let _disposables: Disposable[] = [];
export async function restartServer(

export async function startServer(
projectRoot: vscode.WorkspaceFolder,
workspaceSettings: ISettings,
serverId: string,
serverName: string,
outputChannel: LogOutputChannel,
lsClient?: LanguageClient,
): Promise<LanguageClient | undefined> {
if (lsClient) {
traceInfo(`Server: Stop requested`);
await lsClient.stop();
_disposables.forEach((d) => d.dispose());
_disposables = [];
}

updateStatus(undefined, LanguageStatusSeverity.Information, true);

const extensionSettings = await getExtensionSettings(serverId);
Expand Down Expand Up @@ -454,3 +447,10 @@ export async function restartServer(

return newLSClient;
}

export async function stopServer(lsClient: LanguageClient): Promise<void> {
traceInfo(`Server: Stop requested`);
await lsClient.stop();
_disposables.forEach((d) => d.dispose());
_disposables = [];
}
11 changes: 7 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
onDidChangePythonInterpreter,
resolveInterpreter,
} from "./common/python";
import { restartServer } from "./common/server";
import { startServer, stopServer } from "./common/server";
import {
checkIfConfigurationChanged,
getInterpreterFromSetting,
Expand Down Expand Up @@ -89,6 +89,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
restartInProgress = true;

try {
if (lsClient) {
await stopServer(lsClient);
}

const projectRoot = await getProjectRoot();
const workspaceSettings = await getWorkspaceSettings(serverId, projectRoot);

Expand Down Expand Up @@ -124,13 +128,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
}
}

lsClient = await restartServer(
lsClient = await startServer(
projectRoot,
workspaceSettings,
serverId,
serverName,
outputChannel,
lsClient,
);
} finally {
// Ensure that we reset the flag in case of an error, early return, or success.
Expand Down Expand Up @@ -268,6 +271,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>

export async function deactivate(): Promise<void> {
if (lsClient) {
await lsClient.stop();
await stopServer(lsClient);
}
}

0 comments on commit c21d41a

Please sign in to comment.