diff --git a/pydance/package.json b/pydance/package.json index f65d9f4..623885d 100644 --- a/pydance/package.json +++ b/pydance/package.json @@ -20,18 +20,6 @@ ], "main": "./out/extension.js", "contributes": { - "languages": [ - { - "id": "python", - "aliases": [ - "Python", - "python" - ], - "extensions": [ - ".py" - ] - } - ], "configuration": { "title": "Pydance", "properties": { @@ -40,6 +28,20 @@ "default": "ruff", "enum": ["ruff", "tree-sitter"], "description": "Parser backend to use for Python code analysis" + }, + "pydance.trace.server": { + "type": "string", + "default": "off", + "enum": ["off", "messages", "verbose"], + "description": "Traces the communication between VS Code and the language server" + }, + "pydance.excludePatterns": { + "type": "array", + "default": [], + "items": { + "type": "string" + }, + "description": "Glob patterns for directories to exclude from indexing" } } } diff --git a/pydance/src/extension.ts b/pydance/src/extension.ts index ba39314..0e670ad 100644 --- a/pydance/src/extension.ts +++ b/pydance/src/extension.ts @@ -16,9 +16,11 @@ export function activate(context: vscode.ExtensionContext) { const serverPath = context.asAbsolutePath(path.join("pylight")); outputChannel.appendLine(`Server path: ${serverPath}`); - // Get the parser configuration + // Get configuration const config = vscode.workspace.getConfiguration("pydance"); const parser = config.get("parser", "ruff"); + const traceLevel = config.get("trace.server", "off"); + const excludePatterns = config.get("excludePatterns", []); outputChannel.appendLine(`Using parser: ${parser}`); // If the extension is launched in debug mode then the debug server options are used const serverOptions: ServerOptions = { @@ -30,19 +32,10 @@ export function activate(context: vscode.ExtensionContext) { const clientOptions: LanguageClientOptions = { // Register the server for Python documents documentSelector: [{ scheme: "file", language: "python" }], - synchronize: { - // Notify the server about file changes to Python files in the workspace - fileEvents: vscode.workspace.createFileSystemWatcher( - "**/*.py", - false, - true, - true - ), // Ignore changes in .venv - }, outputChannel: outputChannel, // traceOutputChannel: outputChannel, initializationOptions: { - excludePatterns: ["**/.venv/**", "**/venv/**", "**/.env/**", "**/env/**"], + excludePatterns: excludePatterns, }, }; @@ -55,9 +48,13 @@ export function activate(context: vscode.ExtensionContext) { clientOptions ); - // verbose logging of the LSP client's interactions with the server - // turn off when packaging the extension (make it configurable) - client.setTrace(Trace.Verbose); + // Set trace level based on configuration + const traceMap: { [key: string]: Trace } = { + off: Trace.Off, + messages: Trace.Messages, + verbose: Trace.Verbose, + }; + client.setTrace(traceMap[traceLevel] || Trace.Off); outputChannel.appendLine("Starting language client..."); // Start the client. This will also launch the server diff --git a/pydance/src/test/suite/helper.ts b/pydance/src/test/suite/helper.ts index f6ba55d..4312341 100644 --- a/pydance/src/test/suite/helper.ts +++ b/pydance/src/test/suite/helper.ts @@ -1,11 +1,6 @@ import * as vscode from "vscode"; import * as path from "path"; -export let doc: vscode.TextDocument; -export let editor: vscode.TextEditor; -export let documentEol: string; -export let platformEol: string; - /** * Activates the pydance extension */ @@ -14,8 +9,8 @@ export async function activate(docUri: vscode.Uri) { const ext = vscode.extensions.getExtension("ToughType.pydance")!; await ext.activate(); try { - doc = await vscode.workspace.openTextDocument(docUri); - editor = await vscode.window.showTextDocument(doc); + const doc = await vscode.workspace.openTextDocument(docUri); + await vscode.window.showTextDocument(doc); await sleep(2000); // Wait for language server activation } catch (e) { console.error(e); @@ -26,18 +21,10 @@ async function sleep(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); } -export const getDocPath = (p: string) => { +const getDocPath = (p: string) => { return path.resolve(__dirname, "../../../src/testFixture", p); }; export const getDocUri = (p: string) => { return vscode.Uri.file(getDocPath(p)); }; - -export async function setTestContent(content: string): Promise { - const all = new vscode.Range( - doc.positionAt(0), - doc.positionAt(doc.getText().length) - ); - return editor.edit((eb) => eb.replace(all, content)); -}