From d96f56ba22fdf547791bd932be92038e97b9bfe2 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 14 Mar 2023 23:57:54 -0400 Subject: [PATCH] Pass global settings to the LSP server --- src/common/server.ts | 7 ++++--- src/common/settings.ts | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/common/server.ts b/src/common/server.ts index f92feeb..a3609bb 100644 --- a/src/common/server.ts +++ b/src/common/server.ts @@ -10,11 +10,11 @@ import { import { DEBUG_SERVER_SCRIPT_PATH, SERVER_SCRIPT_PATH } from './constants'; import { traceError, traceInfo, traceLog, traceVerbose } from './log/logging'; import { getDebuggerPath } from './python'; -import { getExtensionSettings, getResourceSettings, ISettings } from './settings'; +import { getExtensionSettings, getGlobalSettings, getWorkspaceSettings, ISettings } from './settings'; import { getProjectRoot, traceLevelToLSTrace } from './utilities'; import { isVirtualWorkspace } from './vscodeapi'; -export type IInitOptions = { settings: ISettings[] }; +export type IInitOptions = { settings: ISettings[]; globalSettings: Omit }; async function getDebugServerOptions( interpreter: string[], @@ -117,7 +117,7 @@ export async function restartServer( } const workspaceFolder = getProjectRoot(); - const resourceSettings = await getResourceSettings(serverId, workspaceFolder?.uri); + const resourceSettings = await getWorkspaceSettings(serverId, workspaceFolder?.uri); if (resourceSettings.interpreter.length === 0) { traceError( 'Python interpreter missing:\r\n' + @@ -134,6 +134,7 @@ export async function restartServer( outputChannel, { settings: await getExtensionSettings(serverId), + globalSettings: await getGlobalSettings(serverId), }, resourceSettings, ); diff --git a/src/common/settings.ts b/src/common/settings.ts index efa981e..0bc4065 100644 --- a/src/common/settings.ts +++ b/src/common/settings.ts @@ -20,7 +20,7 @@ export async function getExtensionSettings(namespace: string): Promise('interpreter'); } -export async function getResourceSettings(namespace: string, resource?: Uri): Promise> { +export async function getWorkspaceSettings(namespace: string, resource?: Uri): Promise> { const config = getConfiguration(namespace, resource); let interpreter: string[] | undefined = getInterpreterFromSetting(namespace); @@ -55,6 +55,23 @@ export async function getResourceSettings(namespace: string, resource?: Uri): Pr }; } +export async function getGlobalSettings(namespace: string): Promise> { + const config = getConfiguration(namespace); + + let interpreter: string[] | undefined = getInterpreterFromSetting(namespace); + + return { + logLevel: config.get(`logLevel`) ?? 'error', + args: config.get(`args`) ?? [], + path: config.get(`path`) ?? [], + interpreter: interpreter ?? [], + importStrategy: config.get(`importStrategy`) ?? 'fromEnvironment', + showNotifications: config.get(`showNotifications`) ?? 'off', + organizeImports: config.get(`organizeImports`) ?? true, + fixAll: config.get(`fixAll`) ?? true, + }; +} + export function checkIfConfigurationChanged(e: ConfigurationChangeEvent, namespace: string): boolean { const settings = [ `${namespace}.trace`,