-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] vscode: Client code cleaning + Python extension integration
Changes: - Remove pythonPath field from Config view - Integrate Python extension - Properly use async/await in the code. - Use of global.d.ts for Global variables. - Wait for LanguageClient to stop before starting it again - Queue Configuration change when LanguageClient is still stopping - Properly hide Crash notification test command in Production - outputChannel is now stored globally instead of being passed to all functions - Logging is now done through LanguageClient - Add a Bash shebang to build_package.sh
- Loading branch information
Showing
16 changed files
with
430 additions
and
381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#!/bin/bash | ||
|
||
PACKAGE_VERSION=$(cat package.json \ | ||
| grep version \ | ||
| head -1 \ | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import * as path from 'path'; | ||
|
||
const folderName = path.basename(__dirname); | ||
export const EXTENSION_ROOT_DIR = | ||
folderName === 'common' ? path.dirname(path.dirname(__dirname)) : path.dirname(__dirname); | ||
export const BUNDLED_PYTHON_SCRIPTS_DIR = path.join(EXTENSION_ROOT_DIR, 'server'); | ||
export const SERVER_SCRIPT_PATH = path.join(BUNDLED_PYTHON_SCRIPTS_DIR, '__main__.py'); | ||
export const DEBUG_SERVER_SCRIPT_PATH = path.join(BUNDLED_PYTHON_SCRIPTS_DIR, `_debug_server.py`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import { commands, Disposable, Event, EventEmitter, Uri } from 'vscode'; | ||
import { PythonExtension, ResolvedEnvironment, VersionInfo } from '@vscode/python-extension'; | ||
|
||
export interface IInterpreterDetails { | ||
path?: string[]; | ||
resource?: Uri; | ||
} | ||
|
||
const onDidChangePythonInterpreterEvent = new EventEmitter<IInterpreterDetails>(); | ||
export const onDidChangePythonInterpreter: Event<IInterpreterDetails> = onDidChangePythonInterpreterEvent.event; | ||
|
||
let _api: PythonExtension | undefined; | ||
async function getPythonExtensionAPI(): Promise<PythonExtension | undefined> { | ||
if (_api) { | ||
return _api; | ||
} | ||
_api = await PythonExtension.api(); | ||
return _api; | ||
} | ||
|
||
export async function initializePython(disposables: Disposable[]): Promise<void> { | ||
try { | ||
const api = await getPythonExtensionAPI(); | ||
|
||
if (api) { | ||
disposables.push( | ||
api.environments.onDidChangeActiveEnvironmentPath((e) => { | ||
onDidChangePythonInterpreterEvent.fire({ path: [e.path], resource: e.resource?.uri }); | ||
}), | ||
); | ||
|
||
console.log('Waiting for interpreter from python extension.'); | ||
onDidChangePythonInterpreterEvent.fire(await getInterpreterDetails()); | ||
} | ||
} catch (error) { | ||
console.error('Error initializing python: ', error); | ||
} | ||
} | ||
|
||
export async function resolveInterpreter(interpreter: string[]): Promise<ResolvedEnvironment | undefined> { | ||
const api = await getPythonExtensionAPI(); | ||
return api?.environments.resolveEnvironment(interpreter[0]); | ||
} | ||
|
||
export async function getInterpreterDetails(resource?: Uri): Promise<IInterpreterDetails> { | ||
const api = await getPythonExtensionAPI(); | ||
const environment = await api?.environments.resolveEnvironment( | ||
api?.environments.getActiveEnvironmentPath(resource), | ||
); | ||
if (environment?.executable.uri && checkVersion(environment)) { | ||
return { path: [environment?.executable.uri.fsPath], resource }; | ||
} | ||
return { path: undefined, resource }; | ||
} | ||
|
||
export async function getDebuggerPath(): Promise<string | undefined> { | ||
const api = await getPythonExtensionAPI(); | ||
return api?.debug.getDebuggerPackagePath(); | ||
} | ||
|
||
export async function runPythonExtensionCommand(command: string, ...rest: any[]) { | ||
await getPythonExtensionAPI(); | ||
return await commands.executeCommand(command, ...rest); | ||
} | ||
|
||
export function checkVersion(resolved: ResolvedEnvironment | undefined): boolean { | ||
const version = resolved?.version; | ||
if (version?.major === 3 && version?.minor >= 8) { | ||
return true; | ||
} | ||
console.error(`Python version ${version?.major}.${version?.minor} is not supported.`); | ||
console.error(`Selected python path: ${resolved?.executable.uri?.fsPath}`); | ||
console.error('Supported versions are 3.8 and above.'); | ||
return false; | ||
} | ||
|
||
export async function getPythonVersion(): Promise<VersionInfo> { | ||
let interpreterDetails = await getInterpreterDetails(); | ||
let resolved = await resolveInterpreter(interpreterDetails.path); | ||
let version = resolved.version; | ||
|
||
return version; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.