Skip to content

Commit

Permalink
Pass global settings to the LSP server
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 15, 2023
1 parent 916d2fd commit d96f56b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/common/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISettings, 'workspace'> };

async function getDebugServerOptions(
interpreter: string[],
Expand Down Expand Up @@ -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' +
Expand All @@ -134,6 +134,7 @@ export async function restartServer(
outputChannel,
{
settings: await getExtensionSettings(serverId),
globalSettings: await getGlobalSettings(serverId),
},
resourceSettings,
);
Expand Down
21 changes: 19 additions & 2 deletions src/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function getExtensionSettings(namespace: string): Promise<ISettings
const workspaces = getWorkspaceFolders();

for (const workspace of workspaces) {
const workspaceSetting = await getResourceSettings(namespace, workspace.uri);
const workspaceSetting = await getWorkspaceSettings(namespace, workspace.uri);
settings.push({
workspace: workspace.uri.toString(),
...workspaceSetting,
Expand All @@ -35,7 +35,7 @@ export function getInterpreterFromSetting(namespace: string): string[] | undefin
return config.get<string[]>('interpreter');
}

export async function getResourceSettings(namespace: string, resource?: Uri): Promise<Omit<ISettings, 'workspace'>> {
export async function getWorkspaceSettings(namespace: string, resource?: Uri): Promise<Omit<ISettings, 'workspace'>> {
const config = getConfiguration(namespace, resource);

let interpreter: string[] | undefined = getInterpreterFromSetting(namespace);
Expand All @@ -55,6 +55,23 @@ export async function getResourceSettings(namespace: string, resource?: Uri): Pr
};
}

export async function getGlobalSettings(namespace: string): Promise<Omit<ISettings, 'workspace'>> {
const config = getConfiguration(namespace);

let interpreter: string[] | undefined = getInterpreterFromSetting(namespace);

return {
logLevel: config.get<LoggingLevelSettingType>(`logLevel`) ?? 'error',
args: config.get<string[]>(`args`) ?? [],
path: config.get<string[]>(`path`) ?? [],
interpreter: interpreter ?? [],
importStrategy: config.get<string>(`importStrategy`) ?? 'fromEnvironment',
showNotifications: config.get<string>(`showNotifications`) ?? 'off',
organizeImports: config.get<boolean>(`organizeImports`) ?? true,
fixAll: config.get<boolean>(`fixAll`) ?? true,
};
}

export function checkIfConfigurationChanged(e: ConfigurationChangeEvent, namespace: string): boolean {
const settings = [
`${namespace}.trace`,
Expand Down

0 comments on commit d96f56b

Please sign in to comment.