Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions pydance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@
],
"main": "./out/extension.js",
"contributes": {
"languages": [
{
"id": "python",
"aliases": [
"Python",
"python"
],
"extensions": [
".py"
]
}
],
"configuration": {
"title": "Pydance",
"properties": {
Expand All @@ -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"
}
}
}
Expand Down
25 changes: 11 additions & 14 deletions pydance/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>("parser", "ruff");
const traceLevel = config.get<string>("trace.server", "off");
const excludePatterns = config.get<string[]>("excludePatterns", []);
outputChannel.appendLine(`Using parser: ${parser}`);
// If the extension is launched in debug mode then the debug server options are used
const serverOptions: ServerOptions = {
Expand All @@ -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,
},
};

Expand All @@ -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
Expand Down
19 changes: 3 additions & 16 deletions pydance/src/test/suite/helper.ts
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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);
Expand All @@ -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<boolean> {
const all = new vscode.Range(
doc.positionAt(0),
doc.positionAt(doc.getText().length)
);
return editor.edit((eb) => eb.replace(all, content));
}
Loading