Skip to content

Commit

Permalink
[IMP] client: Option to disable python extension LanguageServer
Browse files Browse the repository at this point in the history
  • Loading branch information
mmahrouss committed Nov 15, 2024
1 parent e95932e commit 67ca8ee
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
46 changes: 43 additions & 3 deletions vscode/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ function validateState(context: ExtensionContext) {

function setMissingStateVariables(context: ExtensionContext) {
const globalStateKeys = context.globalState.keys();
const workspaceStateKeys = context.workspaceState.keys();
let globalVariables = new Map<string, any>([
["Odoo.nextConfigId", stateInit["Odoo.nextConfigId"]],
["Odoo.stateVersion", stateInit["Odoo.stateVersion"]],
Expand Down Expand Up @@ -233,7 +232,7 @@ async function changeSelectedConfig(context: ExtensionContext, configId: Number)
await workspace.getConfiguration().update("Odoo.selectedConfiguration", configId, ConfigurationTarget.Workspace);
}

async function find_last_log_file(context: ExtensionContext, pid: number) {
async function findLastLogFile(context: ExtensionContext, pid: number) {
let prefix = "odoo_logs";
let suffix = `.${pid}.log`
let cwd = path.join(__dirname, "..", "..");
Expand Down Expand Up @@ -279,7 +278,7 @@ async function displayCrashMessage(context: ExtensionContext, crashInfo: string,
"Cancel"
);

let log_file = await find_last_log_file(context, pid);
let log_file = await findLastLogFile(context, pid);

switch (selection) {
case ("Send crash report"):
Expand All @@ -295,6 +294,9 @@ async function initLanguageServerClient(context: ExtensionContext, outputChannel
let client : LanguageClient;
try {
global.CURRENT_PYTHON_PATH = await getPythonPath(context);
if (workspace.getConfiguration('Odoo').get('disablePythonLanguageServer')){
displayDisablePythonLSMessage();
}

global.SERVER_PID = 0;
let serverPath = "./win_odoo_ls_server.exe";
Expand Down Expand Up @@ -562,6 +564,9 @@ async function initializeSubscriptions(context: ExtensionContext): Promise<void>
global.IS_LOADING = false;
}
await setStatusConfig(context);
if (event.affectsConfiguration("Odoo.disablePythonLanguageServer") && workspace.getConfiguration('Odoo').get('disablePythonLanguageServer')){
displayDisablePythonLSMessage()
}
}
catch (error) {
global.LSCLIENT?.error(error);
Expand Down Expand Up @@ -704,6 +709,9 @@ async function initializeSubscriptions(context: ExtensionContext): Promise<void>
await displayCrashMessage(context, error, global.SERVER_PID, 'odoo.clickStatusBar')
}
}),
commands.registerCommand(
"odoo.disablePythonLanguageServerCommand", setPythonLSNone
)
);

if (context.extensionMode === ExtensionMode.Development) {
Expand Down Expand Up @@ -861,3 +869,35 @@ async function getPythonPath(context, outputLogs: boolean = true): Promise<strin
}
return pythonPath
}

async function setPythonLSNone() {
await workspace.getConfiguration('python').update('languageServer', 'None', ConfigurationTarget.Workspace)
.then(
() => window.showInformationMessage('Python language server set to None for current workspace for Odoo LS to function properly'),
(error) => window.showErrorMessage(`Failed to update setting: ${error}`)
);
}

async function displayDisablePythonLSMessage() {
if (!global.IS_PYTHON_EXTENSION_READY){
return
}
// if python.languageServer is already None do not show the pop-up
if (workspace.getConfiguration('python').get("languageServer") == "None"){
return
}
window.showInformationMessage(
"Disable Python Addon Language server for a better experience",
"Yes",
"No",
"Don't Show again",
).then(async selection => {
switch (selection) {
case "Yes":
await setPythonLSNone();
break;
case "Don't Show again":
await workspace.getConfiguration('Odoo').update('disablePythonLanguageServer', false, ConfigurationTarget.Global)
}
});
}
11 changes: 11 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
"command": "odoo.testCrashMessage",
"title": "Open the crash notification",
"category": "Odoo"
},
{
"command": "odoo.disablePythonLanguageServerCommand",
"title": "Set Python extension LanugageServer to None (Does nothing if python extension is not active)",
"category": "Odoo"
}
],
"views": {},
Expand Down Expand Up @@ -119,6 +124,12 @@
"default": true,
"markdownDescription": "Only show model names from module dependencies"
},
"Odoo.disablePythonLanguageServer": {
"scope": "window",
"type": "boolean",
"default": true,
"markdownDescription": "Set LanugageServer setting on Python extension to None on workspace level after user input (Does nothing if python extension is not active or already set to `None`)"
},
"Odoo.diagMissingImportLevel": {
"scope": "window",
"type": "string",
Expand Down

0 comments on commit 67ca8ee

Please sign in to comment.