pi-lens 3.7.1 → 3.8.2
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.
- package/CHANGELOG.md +217 -0
- package/README.md +706 -619
- package/clients/architect-client.ts +7 -2
- package/clients/ast-grep-client.ts +7 -1
- package/clients/dispatch/plan.ts +10 -4
- package/clients/dispatch/runners/architect.ts +20 -7
- package/clients/dispatch/runners/ast-grep-napi.ts +5 -2
- package/clients/dispatch/runners/ast-grep.ts +29 -18
- package/clients/dispatch/runners/biome.ts +4 -4
- package/clients/dispatch/runners/python-slop.ts +17 -7
- package/clients/dispatch/runners/ruff.ts +4 -4
- package/clients/dispatch/runners/tree-sitter.ts +30 -19
- package/clients/dispatch/runners/ts-slop.ts +17 -7
- package/clients/dispatch/runners/utils/runner-helpers.ts +76 -8
- package/clients/dispatch/utils/format-utils.ts +2 -1
- package/clients/fix-scanners.ts +8 -8
- package/clients/installer/index.ts +19 -1
- package/clients/lsp/index.ts +0 -40
- package/clients/lsp/launch.ts +5 -2
- package/clients/package-root.ts +44 -0
- package/clients/pipeline.ts +179 -8
- package/clients/scan-utils.ts +20 -32
- package/clients/sg-runner.ts +7 -5
- package/clients/source-filter.ts +222 -0
- package/clients/startup-scan.ts +142 -0
- package/clients/todo-scanner.ts +44 -55
- package/clients/tree-sitter-cache.ts +315 -0
- package/clients/tree-sitter-client.ts +208 -52
- package/clients/tree-sitter-fixer.ts +217 -0
- package/clients/tree-sitter-navigator.ts +329 -0
- package/clients/tree-sitter-query-loader.ts +55 -32
- package/commands/booboo.ts +47 -35
- package/default-architect.yaml +76 -87
- package/docs/ARCHITECTURE.md +74 -0
- package/docs/AST_GREP_RULES.md +266 -0
- package/docs/COMPLEXITY_METRICS.md +120 -0
- package/docs/EXCLUSIONS.md +83 -0
- package/docs/LSP_CONFIG.md +240 -0
- package/docs/TREE_SITTER_RULES.md +340 -0
- package/docs/WRITING_NEW_AST_GREP_RULES.md +200 -0
- package/index.ts +209 -86
- package/package.json +13 -4
- package/rules/ast-grep-rules/rules/array-callback-return-js.yml +33 -0
- package/rules/ast-grep-rules/rules/array-callback-return.yml +1 -1
- package/rules/ast-grep-rules/rules/constructor-super-js.yml +22 -0
- package/rules/ast-grep-rules/rules/empty-catch-js.yml +45 -0
- package/rules/ast-grep-rules/rules/empty-catch.yml +1 -1
- package/rules/ast-grep-rules/rules/getter-return-js.yml +59 -0
- package/rules/ast-grep-rules/rules/getter-return.yml +1 -1
- package/rules/ast-grep-rules/rules/hardcoded-url-js.yml +12 -0
- package/rules/ast-grep-rules/rules/jsx-boolean-short-circuit.yml +1 -1
- package/rules/ast-grep-rules/rules/jwt-no-verify-js.yml +14 -0
- package/rules/ast-grep-rules/rules/missed-concurrency-js.yml +25 -0
- package/rules/ast-grep-rules/rules/nested-ternary-js.yml +10 -0
- package/rules/ast-grep-rules/rules/no-alert-js.yml +6 -0
- package/rules/ast-grep-rules/rules/no-architecture-violation.yml +21 -18
- package/rules/ast-grep-rules/rules/no-array-constructor-js.yml +10 -0
- package/rules/ast-grep-rules/rules/no-async-promise-executor-js.yml +15 -0
- package/rules/ast-grep-rules/rules/no-async-promise-executor.yml +1 -1
- package/rules/ast-grep-rules/rules/no-await-in-loop-js.yml +30 -0
- package/rules/ast-grep-rules/rules/no-await-in-promise-all-js.yml +20 -0
- package/rules/ast-grep-rules/rules/no-await-in-promise-all.yml +1 -1
- package/rules/ast-grep-rules/rules/no-bare-except.yml +1 -1
- package/rules/ast-grep-rules/rules/no-case-declarations-js.yml +16 -0
- package/rules/ast-grep-rules/rules/no-compare-neg-zero-js.yml +13 -0
- package/rules/ast-grep-rules/rules/no-compare-neg-zero.yml +1 -1
- package/rules/ast-grep-rules/rules/no-comparison-to-none.yml +1 -1
- package/rules/ast-grep-rules/rules/no-cond-assign-js.yml +36 -0
- package/rules/ast-grep-rules/rules/no-cond-assign.yml +1 -1
- package/rules/ast-grep-rules/rules/no-constant-condition-js.yml +25 -0
- package/rules/ast-grep-rules/rules/no-constant-condition.yml +1 -1
- package/rules/ast-grep-rules/rules/no-constructor-return-js.yml +28 -0
- package/rules/ast-grep-rules/rules/no-constructor-return.yml +1 -1
- package/rules/ast-grep-rules/rules/no-discarded-error-js.yml +25 -0
- package/rules/ast-grep-rules/rules/no-discarded-error.yml +25 -0
- package/rules/ast-grep-rules/rules/no-dupe-args-js.yml +15 -0
- package/rules/ast-grep-rules/rules/no-dupe-keys-js.yml +73 -0
- package/rules/ast-grep-rules/rules/no-extra-boolean-cast-js.yml +25 -0
- package/rules/ast-grep-rules/rules/no-hardcoded-secrets-js.yml +17 -0
- package/rules/ast-grep-rules/rules/no-implied-eval-js.yml +15 -0
- package/rules/ast-grep-rules/rules/no-inner-html-js.yml +13 -0
- package/rules/ast-grep-rules/rules/no-insecure-randomness-js.yml +20 -0
- package/rules/ast-grep-rules/rules/no-insecure-randomness.yml +1 -1
- package/rules/ast-grep-rules/rules/no-javascript-url-js.yml +11 -0
- package/rules/ast-grep-rules/rules/no-nan-comparison-js.yml +22 -0
- package/rules/ast-grep-rules/rules/no-nan-comparison.yml +22 -0
- package/rules/ast-grep-rules/rules/no-new-symbol-js.yml +8 -0
- package/rules/ast-grep-rules/rules/no-new-wrappers-js.yml +13 -0
- package/rules/ast-grep-rules/rules/no-open-redirect-js.yml +15 -0
- package/rules/ast-grep-rules/rules/no-prototype-builtins-js.yml +15 -0
- package/rules/ast-grep-rules/rules/no-prototype-builtins.yml +1 -1
- package/rules/ast-grep-rules/rules/no-sql-in-code-js.yml +13 -0
- package/rules/ast-grep-rules/rules/no-sql-in-code.yml +1 -1
- package/rules/ast-grep-rules/rules/no-throw-string-js.yml +12 -0
- package/rules/ast-grep-rules/rules/no-throw-string.yml +1 -1
- package/rules/ast-grep-rules/rules/strict-equality-js.yml +10 -0
- package/rules/ast-grep-rules/rules/strict-inequality-js.yml +10 -0
- package/rules/ast-grep-rules/rules/toctou-js.yml +112 -0
- package/rules/ast-grep-rules/rules/toctou.yml +1 -1
- package/rules/ast-grep-rules/rules/unchecked-sync-fs-js.yml +44 -0
- package/rules/ast-grep-rules/rules/unchecked-sync-fs.yml +44 -0
- package/rules/ast-grep-rules/rules/unchecked-throwing-call-js.yml +31 -0
- package/rules/ast-grep-rules/rules/unchecked-throwing-call-python.yml +48 -0
- package/rules/ast-grep-rules/rules/unchecked-throwing-call-ruby.yml +47 -0
- package/rules/ast-grep-rules/rules/unchecked-throwing-call.yml +31 -0
- package/rules/ast-grep-rules/rules/weak-rsa-key-js.yml +15 -0
- package/rules/tree-sitter-queries/go/go-bare-error.yml +47 -0
- package/rules/tree-sitter-queries/go/go-defer-in-loop.yml +47 -0
- package/rules/tree-sitter-queries/go/go-hardcoded-secrets.yml +54 -0
- package/rules/tree-sitter-queries/python/is-vs-equals.yml +1 -1
- package/rules/tree-sitter-queries/python/python-debugger.yml +46 -0
- package/rules/tree-sitter-queries/python/python-empty-except.yml +48 -0
- package/rules/tree-sitter-queries/python/python-hardcoded-secrets.yml +44 -0
- package/rules/tree-sitter-queries/python/python-mutable-class-attr.yml +57 -0
- package/rules/tree-sitter-queries/python/python-print-statement.yml +53 -0
- package/rules/tree-sitter-queries/python/python-raise-string.yml +38 -0
- package/rules/tree-sitter-queries/python/python-unsafe-regex.yml +58 -0
- package/rules/tree-sitter-queries/ruby/ruby-debugger.yml +44 -0
- package/rules/tree-sitter-queries/ruby/ruby-empty-rescue.yml +47 -0
- package/rules/tree-sitter-queries/ruby/ruby-eval.yml +43 -0
- package/rules/tree-sitter-queries/ruby/ruby-hardcoded-secrets.yml +40 -0
- package/rules/tree-sitter-queries/ruby/ruby-open-struct.yml +48 -0
- package/rules/tree-sitter-queries/ruby/ruby-puts-statement.yml +52 -0
- package/rules/tree-sitter-queries/ruby/ruby-rescue-exception.yml +51 -0
- package/rules/tree-sitter-queries/ruby/ruby-unsafe-regex.yml +49 -0
- package/rules/tree-sitter-queries/rust/rust-clone-in-loop.yml +49 -0
- package/rules/tree-sitter-queries/rust/rust-unwrap.yml +45 -0
- package/rules/tree-sitter-queries/typescript/console-statement.yml +3 -3
- package/rules/tree-sitter-queries/typescript/hardcoded-secrets.yml +13 -27
- package/rules/tree-sitter-queries/typescript/injections.scm +40 -0
- package/rules/tree-sitter-queries/typescript/no-console-in-tests.yml +52 -0
- package/rules/tree-sitter-queries/typescript/sql-injection.yml +55 -0
- package/rules/tree-sitter-queries/typescript/unsafe-regex.yml +71 -0
- package/rules/tree-sitter-queries/typescript/variable-shadowing.yml +51 -0
- package/scripts/download-grammars.ts +78 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Complexity Metrics
|
|
2
|
+
|
|
3
|
+
pi-lens calculates comprehensive code quality metrics for every source file. These are used by `/lens-tdi` and shown in `/lens-booboo` reports.
|
|
4
|
+
|
|
5
|
+
## Metrics Overview
|
|
6
|
+
|
|
7
|
+
| Metric | Range | Description | Thresholds |
|
|
8
|
+
|--------|-------|-------------|------------|
|
|
9
|
+
| **Maintainability Index (MI)** | 0-100 | Composite score combining complexity, size, and structure | <20: 🔴 Unmaintainable, 20-40: 🟡 Poor, >60: ✅ Good |
|
|
10
|
+
| **Cognitive Complexity** | 0+ | Human mental effort to understand code (nesting penalties) | >20: 🟡 Hard to understand, >50: 🔴 Very complex |
|
|
11
|
+
| **Cyclomatic Complexity** | 1+ | Independent code paths (branch points + 1) | >10: 🟡 Complex function, >20: 🔴 Highly complex |
|
|
12
|
+
| **Max Cyclomatic** | 1+ | Worst function in file | >10 flagged |
|
|
13
|
+
| **Nesting Depth** | 0+ | Maximum block nesting level | >4: 🟡 Deep nesting, >6: 🔴 Excessive |
|
|
14
|
+
| **Code Entropy** | 0-8+ bits | Shannon entropy — unpredictability of code patterns | >4.0: 🟡 Risky, >7.0: 🔴 Very unpredictable |
|
|
15
|
+
| **Halstead Volume** | 0+ | Vocabulary × length — unique ops/operands | High = many different operations |
|
|
16
|
+
|
|
17
|
+
## Formulas
|
|
18
|
+
|
|
19
|
+
### Maintainability Index (Microsoft)
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
MI = max(0, (171 - 5.2*ln(Halstead) - 0.23*Cyclomatic - 16.2*ln(LOC)) * 100/171) + commentBonus
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Where:
|
|
26
|
+
- **Halstead** = Halstead Volume
|
|
27
|
+
- **Cyclomatic** = Average cyclomatic complexity
|
|
28
|
+
- **LOC** = Lines of code
|
|
29
|
+
- **commentBonus** = up to +10% for well-commented code
|
|
30
|
+
|
|
31
|
+
### Cognitive Complexity (SonarSource)
|
|
32
|
+
|
|
33
|
+
- +1 for each structural node (if, for, while, case, catch, switch)
|
|
34
|
+
- +1 for each level of nesting
|
|
35
|
+
- +1 for each && and || in binary expressions
|
|
36
|
+
- Exception: else-if chains don't add nesting
|
|
37
|
+
|
|
38
|
+
### Cyclomatic Complexity (McCabe)
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
M = E - N + 2P
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Where:
|
|
45
|
+
- **E** = Number of edges in control flow graph
|
|
46
|
+
- **N** = Number of nodes
|
|
47
|
+
- **P** = Number of connected components (usually 1)
|
|
48
|
+
|
|
49
|
+
Simplified: Count branch points + 1
|
|
50
|
+
|
|
51
|
+
### Code Entropy (Shannon)
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
H = -Σ(p(i) * log2(p(i)))
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Where:
|
|
58
|
+
- **p(i)** = frequency of token i / total tokens
|
|
59
|
+
|
|
60
|
+
Thresholds:
|
|
61
|
+
- ≤4.0 bits: Predictable, conventional code ✅
|
|
62
|
+
- 4.0-7.0 bits: Moderate complexity 🟡
|
|
63
|
+
- ≥7.0 bits: Unpredictable, hard to maintain 🔴
|
|
64
|
+
|
|
65
|
+
### Halstead Volume
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
V = N * log2(n)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Where:
|
|
72
|
+
- **N** = total operators + operands (program length)
|
|
73
|
+
- **n** = unique operators + operands (vocabulary size)
|
|
74
|
+
|
|
75
|
+
## Technical Debt Index (TDI)
|
|
76
|
+
|
|
77
|
+
The TDI provides a single score (0-100) representing overall codebase health. Lower is better.
|
|
78
|
+
|
|
79
|
+
### Formula
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
TDI = MI-debt(45%) + cognitive(30%) + nesting(10%) + maxCyc(10%) + entropy(5%)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Debt Calculation per Factor
|
|
86
|
+
|
|
87
|
+
| Factor | Debt Formula | Good | Bad |
|
|
88
|
+
|--------|---------------|------|-----|
|
|
89
|
+
| **MI** | `(100 - MI) / 100` | 100 | 0 |
|
|
90
|
+
| **Cognitive** | `min(1, cognitive / 200)` | 0 | ≥500 |
|
|
91
|
+
| **Nesting** | `max(0, nesting - 3) / 7` | ≤3 | ≥10 |
|
|
92
|
+
| **Max Cyclomatic** | `max(0, maxCyc - 10) / 20` | ≤10 | ≥30 |
|
|
93
|
+
| **Entropy** | `max(0, entropy - 4.0) / 3.0` | ≤4.0 | ≥7.0 |
|
|
94
|
+
|
|
95
|
+
### Grades
|
|
96
|
+
|
|
97
|
+
- **A** (0-15%): Excellent codebase health
|
|
98
|
+
- **B** (16-30%): Good, minor improvements possible
|
|
99
|
+
- **C** (31-50%): Moderate debt, consider refactoring
|
|
100
|
+
- **D** (51-70%): Significant debt, plan refactoring
|
|
101
|
+
- **F** (71%+): High debt, immediate attention needed
|
|
102
|
+
|
|
103
|
+
### Usage
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
/lens-tdi # Display TDI score with breakdown by category
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## AI Slop Indicators
|
|
110
|
+
|
|
111
|
+
Metrics suggesting potentially AI-generated low-quality code:
|
|
112
|
+
|
|
113
|
+
- **Low MI + high cognitive + high entropy** = potential spaghetti code
|
|
114
|
+
- **Excessive comments (>40%) + low MI** = hand-holding anti-patterns
|
|
115
|
+
- **Single-use helpers with high entropy** = over-abstraction
|
|
116
|
+
- **Many small functions with high cyclomatic** = fragmented complexity
|
|
117
|
+
|
|
118
|
+
**Usage:**
|
|
119
|
+
- `/lens-booboo` — Shows complexity table for all files
|
|
120
|
+
- `tool_result` — Complexity tracked per file, warnings inline
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# File Exclusions
|
|
2
|
+
|
|
3
|
+
pi-lens automatically excludes certain files from analysis to reduce noise.
|
|
4
|
+
|
|
5
|
+
## Test Files
|
|
6
|
+
|
|
7
|
+
All runners respect test file exclusions.
|
|
8
|
+
|
|
9
|
+
**Excluded patterns:**
|
|
10
|
+
```
|
|
11
|
+
**/*.test.ts **/*.test.tsx **/*.test.js **/*.test.jsx
|
|
12
|
+
**/*.spec.ts **/*.spec.tsx **/*.spec.js **/*.spec.jsx
|
|
13
|
+
**/*.poc.test.ts **/*.poc.test.tsx
|
|
14
|
+
**/test-utils.ts **/test-*.ts
|
|
15
|
+
**/__tests__/** **/tests/** **/test/**
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**Why:** Test files intentionally duplicate patterns and have different complexity standards.
|
|
19
|
+
|
|
20
|
+
## Build Artifacts (Source-Filter Module)
|
|
21
|
+
|
|
22
|
+
**New in 3.8.0:** pi-lens uses **sibling-file detection** via `clients/source-filter.ts` to eliminate build artifacts:
|
|
23
|
+
|
|
24
|
+
**How it works:**
|
|
25
|
+
- For each file, check if a "higher precedence" source sibling exists
|
|
26
|
+
- If yes, skip as build artifact; if no, keep as hand-written source
|
|
27
|
+
|
|
28
|
+
**Source precedence rules:**
|
|
29
|
+
| Source Extension | Shadows (Excluded) |
|
|
30
|
+
|------------------|-------------------|
|
|
31
|
+
| `.ts` | `.js`, `.mjs`, `.cjs` |
|
|
32
|
+
| `.tsx` | `.jsx`, `.js`, `.mjs`, `.cjs` |
|
|
33
|
+
| `.vue` | `.js`, `.mjs` |
|
|
34
|
+
| `.svelte` | `.js`, `.mjs` |
|
|
35
|
+
| `.coffee` | `.js` |
|
|
36
|
+
|
|
37
|
+
**Example:**
|
|
38
|
+
```
|
|
39
|
+
src/
|
|
40
|
+
utils.ts ✓ Kept (source)
|
|
41
|
+
utils.js ✗ Excluded (has .ts sibling)
|
|
42
|
+
|
|
43
|
+
manual.js ✓ Kept (no higher-precedence sibling)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Benefits:**
|
|
47
|
+
- Works in mixed TS/JS projects (pure JS files kept when no TS sibling)
|
|
48
|
+
- Handles Vue/Svelte → JavaScript compilation
|
|
49
|
+
- No dependency on `tsconfig.json` detection
|
|
50
|
+
|
|
51
|
+
## Excluded Directories
|
|
52
|
+
|
|
53
|
+
| Directory | Reason |
|
|
54
|
+
|-----------|--------|
|
|
55
|
+
| `node_modules/` | Third-party dependencies |
|
|
56
|
+
| `.git/` | Version control metadata |
|
|
57
|
+
| `dist/`, `build/` | Build outputs |
|
|
58
|
+
| `.pi-lens/`, `.pi/` | pi agent internal files |
|
|
59
|
+
| `.next/`, `.ruff_cache/` | Framework/build caches |
|
|
60
|
+
| `coverage/` | Test coverage reports |
|
|
61
|
+
|
|
62
|
+
## Per-Runner Summary
|
|
63
|
+
|
|
64
|
+
| Runner | Test Files | Build Artifacts | Directories |
|
|
65
|
+
|--------|-----------|-----------------|-------------|
|
|
66
|
+
| **dispatch runners** | ✅ `skipTestFiles` | ✅ `isBuildArtifact()` from source-filter | ✅ `EXCLUDED_DIRS` |
|
|
67
|
+
| **booboo /lens-booboo** | ✅ `shouldIncludeFile()` | ✅ `collectSourceFiles()` from source-filter | ✅ `EXCLUDED_DIRS` |
|
|
68
|
+
| **Secrets scan** | ❌ No exclusion (security) | ❌ No exclusion | ✅ Dirs excluded |
|
|
69
|
+
|
|
70
|
+
Secrets scanning excludes nothing — security takes precedence over noise reduction.
|
|
71
|
+
|
|
72
|
+
**API:**
|
|
73
|
+
```typescript
|
|
74
|
+
// Check if a file is a build artifact
|
|
75
|
+
import { isBuildArtifact } from "./clients/source-filter.js";
|
|
76
|
+
if (isBuildArtifact("src/utils.js")) {
|
|
77
|
+
// Has src/utils.ts sibling → skip
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Collect deduplicated source files
|
|
81
|
+
import { collectSourceFiles } from "./clients/source-filter.js";
|
|
82
|
+
const files = collectSourceFiles("./src"); // No build artifacts
|
|
83
|
+
```
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# LSP Configuration Guide
|
|
2
|
+
|
|
3
|
+
pi-lens supports **31 built-in LSP servers** covering most popular languages. If you need additional servers or want to customize existing ones, you can define them via configuration.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
Create `.pi-lens/lsp.json` in your project root:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"servers": {
|
|
12
|
+
"graphql": {
|
|
13
|
+
"name": "GraphQL Language Server",
|
|
14
|
+
"extensions": [".graphql", ".gql"],
|
|
15
|
+
"command": "graphql-lsp",
|
|
16
|
+
"args": ["server", "--method=stream"]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Configuration File
|
|
23
|
+
|
|
24
|
+
pi-lens looks for config in these locations (first found wins):
|
|
25
|
+
|
|
26
|
+
1. `.pi-lens/lsp.json`
|
|
27
|
+
2. `.pi-lens.json`
|
|
28
|
+
3. `pi-lsp.json`
|
|
29
|
+
|
|
30
|
+
## Server Definition
|
|
31
|
+
|
|
32
|
+
Each server requires:
|
|
33
|
+
|
|
34
|
+
| Field | Type | Description |
|
|
35
|
+
|-------|------|-------------|
|
|
36
|
+
| `name` | string | Display name |
|
|
37
|
+
| `extensions` | string[] | File extensions (e.g., [".rs"]) |
|
|
38
|
+
| `command` | string | Executable name or path |
|
|
39
|
+
| `args` | string[] | Command arguments (optional) |
|
|
40
|
+
| `rootMarkers` | string[] | Files that indicate project root (optional) |
|
|
41
|
+
| `env` | object | Environment variables (optional) |
|
|
42
|
+
|
|
43
|
+
## Examples
|
|
44
|
+
|
|
45
|
+
### GraphQL
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"servers": {
|
|
50
|
+
"graphql": {
|
|
51
|
+
"name": "GraphQL Language Server",
|
|
52
|
+
"extensions": [".graphql", ".gql"],
|
|
53
|
+
"command": "graphql-lsp",
|
|
54
|
+
"args": ["server", "--method=stream"]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Install first: `npm i -g @graphql-codegen/cli graphql-language-service-cli`
|
|
61
|
+
|
|
62
|
+
### Scala (Metals)
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"servers": {
|
|
67
|
+
"scala": {
|
|
68
|
+
"name": "Metals",
|
|
69
|
+
"extensions": [".scala", ".sc"],
|
|
70
|
+
"command": "metals",
|
|
71
|
+
"args": ["-Dmetals.http=false"],
|
|
72
|
+
"rootMarkers": ["build.sbt", ".scala-build"]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Install first: `cs install metals`
|
|
79
|
+
|
|
80
|
+
### R Language Server
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"servers": {
|
|
85
|
+
"r": {
|
|
86
|
+
"name": "R Language Server",
|
|
87
|
+
"extensions": [".r", ".R"],
|
|
88
|
+
"command": "R",
|
|
89
|
+
"args": ["--slave", "-e", "languageserver::run()"]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Install first: `R -e "install.packages('languageserver')"`
|
|
96
|
+
|
|
97
|
+
### Astro
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"servers": {
|
|
102
|
+
"astro": {
|
|
103
|
+
"name": "Astro Language Server",
|
|
104
|
+
"extensions": [".astro"],
|
|
105
|
+
"command": "astro-ls",
|
|
106
|
+
"args": ["--stdio"]
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Install first: `npm i -g @astrojs/language-server`
|
|
113
|
+
|
|
114
|
+
## Disabling Built-in Servers
|
|
115
|
+
|
|
116
|
+
To disable a built-in server (e.g., if you prefer a different one):
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"disabledServers": ["typescript", "eslint"]
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Environment Variables
|
|
125
|
+
|
|
126
|
+
Set custom environment for a server:
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"servers": {
|
|
131
|
+
"python": {
|
|
132
|
+
"name": "Pyright with venv",
|
|
133
|
+
"extensions": [".py"],
|
|
134
|
+
"command": "pyright-langserver",
|
|
135
|
+
"args": ["--stdio"],
|
|
136
|
+
"env": {
|
|
137
|
+
"PYTHONPATH": "/path/to/my/venv/lib/python3.11/site-packages"
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Complete Example
|
|
145
|
+
|
|
146
|
+
```json
|
|
147
|
+
{
|
|
148
|
+
"servers": {
|
|
149
|
+
"graphql": {
|
|
150
|
+
"name": "GraphQL Language Server",
|
|
151
|
+
"extensions": [".graphql", ".gql"],
|
|
152
|
+
"command": "graphql-lsp",
|
|
153
|
+
"args": ["server", "--method=stream"],
|
|
154
|
+
"rootMarkers": [".graphqlconfig", "codegen.yml"]
|
|
155
|
+
},
|
|
156
|
+
"toml": {
|
|
157
|
+
"name": "Taplo (TOML)",
|
|
158
|
+
"extensions": [".toml"],
|
|
159
|
+
"command": "taplo",
|
|
160
|
+
"args": ["lsp", "stdio"]
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
"disabledServers": ["eslint"]
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Auto-Installation
|
|
168
|
+
|
|
169
|
+
For the **31 built-in servers**, pi-lens can auto-install via npm/pip when `--lens-lsp` is enabled:
|
|
170
|
+
|
|
171
|
+
- TypeScript: `typescript-language-server`
|
|
172
|
+
- Python: `pyright`
|
|
173
|
+
- Vue: `@vue/language-server`
|
|
174
|
+
- Svelte: `svelte-language-server`
|
|
175
|
+
- And more...
|
|
176
|
+
|
|
177
|
+
**Custom servers** must be installed manually before use.
|
|
178
|
+
|
|
179
|
+
## Troubleshooting
|
|
180
|
+
|
|
181
|
+
### Server not found
|
|
182
|
+
|
|
183
|
+
Check that the command is in your PATH:
|
|
184
|
+
```bash
|
|
185
|
+
which graphql-lsp
|
|
186
|
+
# or
|
|
187
|
+
graphql-lsp --version
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### LSP not starting
|
|
191
|
+
|
|
192
|
+
Enable debug mode to see errors:
|
|
193
|
+
```bash
|
|
194
|
+
pi --lens-lsp --lens-verbose
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Root detection failing
|
|
198
|
+
|
|
199
|
+
Add appropriate `rootMarkers` for your project structure:
|
|
200
|
+
```json
|
|
201
|
+
{
|
|
202
|
+
"rootMarkers": ["package.json", ".git", "my-project.config.js"]
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Built-in Servers (31 Total)
|
|
207
|
+
|
|
208
|
+
| Language | Server |
|
|
209
|
+
|----------|--------|
|
|
210
|
+
| TypeScript/JavaScript | typescript-language-server |
|
|
211
|
+
| Python | pyright |
|
|
212
|
+
| Go | gopls |
|
|
213
|
+
| Rust | rust-analyzer |
|
|
214
|
+
| Ruby | ruby-lsp |
|
|
215
|
+
| PHP | intelephense |
|
|
216
|
+
| C# | csharp-ls |
|
|
217
|
+
| F# | fsautocomplete |
|
|
218
|
+
| Java | JDTLS |
|
|
219
|
+
| Kotlin | kotlin-language-server |
|
|
220
|
+
| Swift | sourcekit-lsp |
|
|
221
|
+
| Dart | dart |
|
|
222
|
+
| Lua | lua-language-server |
|
|
223
|
+
| C/C++ | clangd |
|
|
224
|
+
| Zig | zls |
|
|
225
|
+
| Haskell | haskell-language-server |
|
|
226
|
+
| Elixir | elixir-ls |
|
|
227
|
+
| Gleam | gleam |
|
|
228
|
+
| OCaml | ocamllsp |
|
|
229
|
+
| Clojure | clojure-lsp |
|
|
230
|
+
| Terraform | terraform-ls |
|
|
231
|
+
| Nix | nixd |
|
|
232
|
+
| Bash | bash-language-server |
|
|
233
|
+
| Docker | dockerfile-language-server |
|
|
234
|
+
| YAML | yaml-language-server |
|
|
235
|
+
| JSON | vscode-json-languageserver |
|
|
236
|
+
| Prisma | @prisma/language-server |
|
|
237
|
+
| **Vue** | @vue/language-server |
|
|
238
|
+
| **Svelte** | svelte-language-server |
|
|
239
|
+
| **ESLint** | vscode-eslint |
|
|
240
|
+
| **CSS/SCSS** | vscode-css-languageserver |
|