fix(lsp): support server workspace configuration

This commit is contained in:
2026-05-05 23:44:21 -04:00
parent 81ab984a86
commit 99ce79ac88
3 changed files with 85 additions and 3 deletions

View File

@@ -3,8 +3,42 @@
//
// Add new servers here. `match` is a list of file extensions (no dot) OR
// language ids; either matches.
import * as fs from "node:fs";
import * as path from "node:path";
import type { ServerConfig } from "./src/types.ts";
// Resolve Python Path - Prefer the project's virtualenv when present so
// Pyright sees the same interpreter/dependencies as project commands.
function resolvePythonPath(rootDir: string): string | undefined {
const candidates = [
path.join(rootDir, ".venv", "bin", "python"),
path.join(rootDir, "venv", "bin", "python"),
];
return candidates.find((candidate) => fs.existsSync(candidate));
}
// Pyright Settings - Minimal editor settings needed for diagnostics and import
// resolution. Shared by workspace/configuration and didChangeConfiguration.
function pyrightSettings(rootDir: string): {
pythonPath: string | undefined;
analysis: {
diagnosticMode: string;
typeCheckingMode: string;
autoSearchPaths: boolean;
useLibraryCodeForTypes: boolean;
};
} {
return {
pythonPath: resolvePythonPath(rootDir),
analysis: {
diagnosticMode: "openFilesOnly",
typeCheckingMode: "basic",
autoSearchPaths: true,
useLibraryCodeForTypes: true,
},
};
}
// Global Root Markers — appended to every server's rootMarkers list
export const globalRootMarkers = [".git"];
@@ -32,6 +66,15 @@ export const servers: ServerConfig[] = [
args: ["--stdio"],
rootMarkers: ["pyproject.toml", "setup.py", "setup.cfg"],
languageId: "python",
workspaceConfiguration: {
initialSettings: ({ rootDir }) => ({ python: pyrightSettings(rootDir) }),
getSection: (section, { rootDir }) => {
const settings = pyrightSettings(rootDir);
if (section === "python") return settings;
if (section === "python.analysis") return settings.analysis;
return null;
},
},
},
{
id: "lua-language-server",