-
Notifications
You must be signed in to change notification settings - Fork 11
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
[IMP] Client side code cleaning and Python extension integration #85
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8701ceb
[IMP] vscode: Client code cleaning + Python extension integration
Louciole 5e09ed0
[IMP] vscode: allow Odoo extension to work standalone and with vscode…
Louciole 43c6aa4
[FIX] vscode: crash when using python2.7 in standalone mode
Louciole 6880d8e
[REF] vscode: change logic of initLanguageServer and getPythonPath
Louciole 8236788
[REF] vscode: debug client restart after removing python extension
Louciole 9401ddd
[FIX] client: fix change config when disabled and pythonExtensionMode
Louciole b50c2c6
[FIX] client: saving confing in pythonExtensionMode
Louciole File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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; | ||
} | ||
|
||
export 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we sure it will never become invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only use this Promise right after getting it and getting it each time we need it to be as close to the current configuration as we can be so there's no reason for it to be invalid in the current setup (but maybe I didn't understand the comment)