@treedy/pyright-mcp 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,54 +0,0 @@
1
- import { z } from 'zod';
2
- import { getLspClient } from '../lsp-client.js';
3
- import { toPosition } from '../utils/position.js';
4
- export const signatureHelpSchema = {
5
- file: z.string().describe('Absolute path to the Python file'),
6
- line: z.number().int().positive().describe('Line number (1-based)'),
7
- column: z.number().int().positive().describe('Column number (1-based)'),
8
- };
9
- export async function signatureHelp(args) {
10
- const client = getLspClient();
11
- const position = toPosition(args.line, args.column);
12
- const result = await client.signatureHelp(args.file, position);
13
- if (!result || result.signatures.length === 0) {
14
- return {
15
- content: [{ type: 'text', text: 'No signature help available at this position.' }],
16
- };
17
- }
18
- let output = `**Signature Help** at ${args.file}:${args.line}:${args.column}\n\n`;
19
- const activeIndex = result.activeSignature ?? 0;
20
- const activeParam = result.activeParameter ?? 0;
21
- for (let i = 0; i < result.signatures.length; i++) {
22
- const sig = result.signatures[i];
23
- const isActive = i === activeIndex;
24
- output += `${isActive ? '→ ' : ' '}**${sig.label}**\n`;
25
- if (sig.documentation) {
26
- const doc = typeof sig.documentation === 'string'
27
- ? sig.documentation
28
- : sig.documentation.value;
29
- output += ` ${doc}\n`;
30
- }
31
- if (sig.parameters && sig.parameters.length > 0) {
32
- output += `\n Parameters:\n`;
33
- for (let j = 0; j < sig.parameters.length; j++) {
34
- const param = sig.parameters[j];
35
- const isActiveParam = isActive && j === activeParam;
36
- const label = typeof param.label === 'string'
37
- ? param.label
38
- : sig.label.slice(param.label[0], param.label[1]);
39
- output += ` ${isActiveParam ? '→ ' : ' '}${label}`;
40
- if (param.documentation) {
41
- const paramDoc = typeof param.documentation === 'string'
42
- ? param.documentation
43
- : param.documentation.value;
44
- output += ` - ${paramDoc}`;
45
- }
46
- output += '\n';
47
- }
48
- }
49
- output += '\n';
50
- }
51
- return {
52
- content: [{ type: 'text', text: output }],
53
- };
54
- }
@@ -1,147 +0,0 @@
1
- import { z } from 'zod';
2
- import { execSync } from 'child_process';
3
- import { existsSync, readFileSync } from 'fs';
4
- import { join } from 'path';
5
- import { findProjectRoot } from '../utils/position.js';
6
- export const statusSchema = {
7
- file: z.string().describe('A Python file path to check the project status for'),
8
- };
9
- export async function status(args) {
10
- const { file } = args;
11
- const lines = [];
12
- // Find project root
13
- const projectRoot = findProjectRoot(file);
14
- lines.push(`## Project Root`);
15
- lines.push(`\`${projectRoot}\``);
16
- lines.push('');
17
- // Check pyright installation
18
- lines.push(`## Pyright`);
19
- try {
20
- const pyrightVersion = execSync('pyright --version', { encoding: 'utf-8' }).trim();
21
- lines.push(`- Version: ${pyrightVersion}`);
22
- }
23
- catch {
24
- lines.push(`- ⚠️ **Not installed or not in PATH**`);
25
- lines.push(` Install with: \`npm install -g pyright\``);
26
- }
27
- lines.push('');
28
- // Check pyright config
29
- lines.push(`## Pyright Config`);
30
- const pyrightConfigPath = join(projectRoot, 'pyrightconfig.json');
31
- const pyprojectPath = join(projectRoot, 'pyproject.toml');
32
- if (existsSync(pyrightConfigPath)) {
33
- lines.push(`- Config file: \`pyrightconfig.json\``);
34
- try {
35
- const config = JSON.parse(readFileSync(pyrightConfigPath, 'utf-8'));
36
- if (config.pythonVersion) {
37
- lines.push(`- Python version: ${config.pythonVersion}`);
38
- }
39
- if (config.pythonPlatform) {
40
- lines.push(`- Platform: ${config.pythonPlatform}`);
41
- }
42
- if (config.venvPath) {
43
- lines.push(`- Venv path: ${config.venvPath}`);
44
- }
45
- if (config.venv) {
46
- lines.push(`- Venv: ${config.venv}`);
47
- }
48
- if (config.typeCheckingMode) {
49
- lines.push(`- Type checking mode: ${config.typeCheckingMode}`);
50
- }
51
- if (config.include) {
52
- lines.push(`- Include: ${JSON.stringify(config.include)}`);
53
- }
54
- if (config.exclude) {
55
- lines.push(`- Exclude: ${JSON.stringify(config.exclude)}`);
56
- }
57
- }
58
- catch (e) {
59
- lines.push(`- ⚠️ Failed to parse config: ${e}`);
60
- }
61
- }
62
- else if (existsSync(pyprojectPath)) {
63
- lines.push(`- Config file: \`pyproject.toml\` (may contain [tool.pyright] section)`);
64
- }
65
- else {
66
- lines.push(`- ⚠️ No pyrightconfig.json or pyproject.toml found`);
67
- lines.push(` Pyright will use default settings`);
68
- }
69
- lines.push('');
70
- // Check Python environment
71
- lines.push(`## Python Environment`);
72
- try {
73
- const pythonVersion = execSync('python3 --version', { encoding: 'utf-8' }).trim();
74
- lines.push(`- System Python: ${pythonVersion}`);
75
- }
76
- catch {
77
- try {
78
- const pythonVersion = execSync('python --version', { encoding: 'utf-8' }).trim();
79
- lines.push(`- System Python: ${pythonVersion}`);
80
- }
81
- catch {
82
- lines.push(`- ⚠️ Python not found in PATH`);
83
- }
84
- }
85
- // Check for virtual environment
86
- const venvPaths = ['.venv', 'venv', '.env', 'env'];
87
- for (const venv of venvPaths) {
88
- const venvPath = join(projectRoot, venv);
89
- if (existsSync(venvPath)) {
90
- lines.push(`- Virtual env found: \`${venv}/\``);
91
- // Try to get venv python version
92
- const venvPython = join(venvPath, 'bin', 'python');
93
- if (existsSync(venvPython)) {
94
- try {
95
- const venvVersion = execSync(`"${venvPython}" --version`, { encoding: 'utf-8' }).trim();
96
- lines.push(` - ${venvVersion}`);
97
- }
98
- catch {
99
- // ignore
100
- }
101
- }
102
- break;
103
- }
104
- }
105
- lines.push('');
106
- // Quick pyright check on the file
107
- lines.push(`## File Check`);
108
- lines.push(`- File: \`${file}\``);
109
- if (existsSync(file)) {
110
- lines.push(`- Exists: ✅`);
111
- try {
112
- const result = execSync(`pyright "${file}" --outputjson`, {
113
- encoding: 'utf-8',
114
- cwd: projectRoot,
115
- timeout: 30000,
116
- });
117
- const output = JSON.parse(result);
118
- const errors = output.generalDiagnostics?.filter((d) => d.severity === 'error')?.length || 0;
119
- const warnings = output.generalDiagnostics?.filter((d) => d.severity === 'warning')?.length || 0;
120
- lines.push(`- Diagnostics: ${errors} errors, ${warnings} warnings`);
121
- }
122
- catch (e) {
123
- // pyright returns non-zero exit code if there are errors
124
- const error = e;
125
- if (error.stdout) {
126
- try {
127
- const output = JSON.parse(error.stdout);
128
- const errors = output.generalDiagnostics?.filter((d) => d.severity === 'error')?.length || 0;
129
- const warnings = output.generalDiagnostics?.filter((d) => d.severity === 'warning')?.length || 0;
130
- lines.push(`- Diagnostics: ${errors} errors, ${warnings} warnings`);
131
- }
132
- catch {
133
- lines.push(`- ⚠️ Could not run pyright check`);
134
- }
135
- }
136
- else {
137
- lines.push(`- ⚠️ Could not run pyright check`);
138
- }
139
- }
140
- }
141
- else {
142
- lines.push(`- Exists: ❌ File not found`);
143
- }
144
- return {
145
- content: [{ type: 'text', text: lines.join('\n') }],
146
- };
147
- }
@@ -1,74 +0,0 @@
1
- import { Position } from 'vscode-languageserver-protocol';
2
- import { existsSync } from 'fs';
3
- import { dirname, join, resolve } from 'path';
4
- /**
5
- * Convert 1-based line/column (user input) to 0-based LSP Position
6
- */
7
- export function toPosition(line, column) {
8
- return Position.create(line - 1, column - 1);
9
- }
10
- /**
11
- * Convert 0-based LSP Position to 1-based line/column (user output)
12
- */
13
- export function fromPosition(pos) {
14
- return {
15
- line: pos.line + 1,
16
- column: pos.character + 1,
17
- };
18
- }
19
- /**
20
- * Format a Location for display
21
- */
22
- export function formatLocation(loc) {
23
- const start = fromPosition(loc.range.start);
24
- const end = fromPosition(loc.range.end);
25
- return `${loc.uri}:${start.line}:${start.column}-${end.line}:${end.column}`;
26
- }
27
- /**
28
- * Format a Range for display
29
- */
30
- export function formatRange(range) {
31
- const start = fromPosition(range.start);
32
- const end = fromPosition(range.end);
33
- return `${start.line}:${start.column}-${end.line}:${end.column}`;
34
- }
35
- /**
36
- * Convert file path to URI
37
- */
38
- export function pathToUri(filePath) {
39
- if (filePath.startsWith('file://')) {
40
- return filePath;
41
- }
42
- return `file://${filePath}`;
43
- }
44
- /**
45
- * Convert URI to file path
46
- */
47
- export function uriToPath(uri) {
48
- if (uri.startsWith('file://')) {
49
- return uri.slice(7);
50
- }
51
- return uri;
52
- }
53
- /**
54
- * Find project root by looking for pyrightconfig.json or pyproject.toml
55
- * starting from the given file path and walking up the directory tree
56
- */
57
- export function findProjectRoot(filePath) {
58
- const configFiles = ['pyrightconfig.json', 'pyproject.toml', '.git'];
59
- let dir = dirname(resolve(filePath));
60
- const root = '/';
61
- while (dir !== root) {
62
- for (const configFile of configFiles) {
63
- if (existsSync(join(dir, configFile))) {
64
- return dir;
65
- }
66
- }
67
- const parent = dirname(dir);
68
- if (parent === dir)
69
- break;
70
- dir = parent;
71
- }
72
- // Fallback to file's directory
73
- return dirname(resolve(filePath));
74
- }