|
| 1 | +# Selective Language Service Disabling |
| 2 | + |
| 3 | +Pyrefly's LSP server now supports selective disabling of individual language services. This allows users to choose exactly which IDE features they want enabled, providing flexibility for different workflows and preferences. |
| 4 | + |
| 5 | +## Available Language Services |
| 6 | + |
| 7 | +The following language services can be selectively disabled: |
| 8 | + |
| 9 | +1. **definition** - Go-to-definition |
| 10 | +2. **typeDefinition** - Go-to-type-definition |
| 11 | +3. **codeAction** - Code actions (quick fixes) |
| 12 | +4. **completion** - Autocomplete |
| 13 | +5. **documentHighlight** - Highlight references |
| 14 | +6. **references** - Find references |
| 15 | +7. **rename** - Rename symbol |
| 16 | +8. **signatureHelp** - Parameter hints |
| 17 | +9. **hover** - Hover tooltips |
| 18 | +10. **inlayHint** - Inlay hints |
| 19 | +11. **documentSymbol** - Document symbols (outline) |
| 20 | +12. **workspaceSymbol** - Workspace-wide symbol search |
| 21 | +13. **semanticTokens** - Semantic highlighting |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +### VSCode Extension |
| 26 | + |
| 27 | +Add the following to your VSCode settings (`.vscode/settings.json` or user settings): |
| 28 | + |
| 29 | +```json |
| 30 | +{ |
| 31 | + "python.pyrefly.disabledLanguageServices": { |
| 32 | + "hover": true, |
| 33 | + "documentSymbol": true |
| 34 | + } |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +This example disables hover tooltips and document symbols (outline), while keeping all other services enabled. |
| 39 | + |
| 40 | +### Command-Line Arguments |
| 41 | + |
| 42 | +When starting the LSP server manually, you can use command-line flags: |
| 43 | + |
| 44 | +```bash |
| 45 | +pyrefly lsp --disable-hover --disable-document-symbol |
| 46 | +``` |
| 47 | + |
| 48 | +Available flags: |
| 49 | +- `--disable-definition` |
| 50 | +- `--disable-type-definition` |
| 51 | +- `--disable-code-action` |
| 52 | +- `--disable-completion` |
| 53 | +- `--disable-document-highlight` |
| 54 | +- `--disable-references` |
| 55 | +- `--disable-rename` |
| 56 | +- `--disable-signature-help` |
| 57 | +- `--disable-hover` |
| 58 | +- `--disable-inlay-hint` |
| 59 | +- `--disable-document-symbol` |
| 60 | +- `--disable-workspace-symbol` |
| 61 | +- `--disable-semantic-tokens` |
| 62 | + |
| 63 | +### Passing Arguments via VSCode Extension |
| 64 | + |
| 65 | +You can also pass these command-line arguments through the VSCode extension settings: |
| 66 | + |
| 67 | +```json |
| 68 | +{ |
| 69 | + "pyrefly.lspArguments": [ |
| 70 | + "lsp", |
| 71 | + "--disable-hover", |
| 72 | + "--disable-document-symbol" |
| 73 | + ] |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +## Implementation Details |
| 78 | + |
| 79 | +### Architecture Decision |
| 80 | + |
| 81 | +The selective disabling is implemented at the **binary level** (LSP server) rather than the VSCode extension level. This design decision provides several benefits: |
| 82 | + |
| 83 | +1. **Cross-editor compatibility** - Works with any editor that uses Pyrefly's LSP server |
| 84 | +2. **Cleaner architecture** - The server respects capabilities rather than the client filtering |
| 85 | +3. **Performance** - Server doesn't process requests for disabled services |
| 86 | +4. **Maintainability** - Logic is centralized in one place |
| 87 | + |
| 88 | +### How It Works |
| 89 | + |
| 90 | +1. **Initialization**: Disabled services are communicated to the server via: |
| 91 | + - Command-line arguments (stored in `LspArgs`) |
| 92 | + - IDE configuration (sent via `workspace/configuration` request) |
| 93 | + |
| 94 | +2. **Capability Negotiation**: The server's `capabilities` function checks disabled services and omits them from the advertised capabilities during LSP initialization. |
| 95 | + |
| 96 | +3. **Runtime Checks**: For services that are disabled via IDE configuration after initialization, the server performs runtime checks before processing requests. |
| 97 | + |
| 98 | +## Use Cases |
| 99 | + |
| 100 | +### Scenario 1: Performance Optimization |
| 101 | + |
| 102 | +If you're working on a very large codebase and find that certain language services are slow, you can disable them to improve performance: |
| 103 | + |
| 104 | +```json |
| 105 | +{ |
| 106 | + "python.pyrefly.disabledLanguageServices": { |
| 107 | + "references": true, |
| 108 | + "workspaceSymbol": true |
| 109 | + } |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +### Scenario 2: Conflict Resolution |
| 114 | + |
| 115 | +If you're using multiple language servers and want to use Pyrefly for type checking but another server for certain features: |
| 116 | + |
| 117 | +```json |
| 118 | +{ |
| 119 | + "python.pyrefly.disabledLanguageServices": { |
| 120 | + "completion": true, |
| 121 | + "hover": true |
| 122 | + } |
| 123 | +} |
| 124 | +``` |
| 125 | + |
| 126 | +### Scenario 3: Minimal Mode |
| 127 | + |
| 128 | +For a minimal setup with only type checking and go-to-definition: |
| 129 | + |
| 130 | +```json |
| 131 | +{ |
| 132 | + "python.pyrefly.disabledLanguageServices": { |
| 133 | + "hover": true, |
| 134 | + "completion": true, |
| 135 | + "signatureHelp": true, |
| 136 | + "documentHighlight": true, |
| 137 | + "documentSymbol": true, |
| 138 | + "workspaceSymbol": true, |
| 139 | + "semanticTokens": true, |
| 140 | + "inlayHint": true |
| 141 | + } |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +## Backward Compatibility |
| 146 | + |
| 147 | +The existing `python.pyrefly.disableLanguageServices` boolean setting still works and will disable **all** language services when set to `true`. The new selective disabling is fully backward compatible. |
| 148 | + |
| 149 | +## Testing |
| 150 | + |
| 151 | +The implementation includes comprehensive tests to ensure: |
| 152 | +- Individual services can be disabled independently |
| 153 | +- Other services continue to work when one is disabled |
| 154 | +- Configuration changes are applied correctly |
| 155 | +- Command-line arguments work as expected |
| 156 | + |
| 157 | +Run tests with: |
| 158 | +```bash |
| 159 | +cargo test --package pyrefly --lib test::lsp::lsp_interaction::configuration |
| 160 | +``` |
0 commit comments