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
7 changes: 6 additions & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ directory, and rust-analyzer and ocaml-lsp install into the active rustup
toolchain and opam switch. Every installing plugin declares a
`userConfig.auto_install` boolean
(default `true`); the hook reads it as `CLAUDE_PLUGIN_OPTION_AUTO_INSTALL` and
skips the install when it is off.
skips the install when it is off. Plugins that launch `code lsp-server` or
`code lsp-multiplex` also pass the option to the server process as
`CODE_LSP_AUTO_INSTALL` through the lspServers `env`, and
`autoInstallDisabled()` in `packages/lsp/src/server/utils.ts` then stops each
server's spawn-time download or install (GitHub releases, `npm install` into
`~/.cache/dora/`, `dotnet tool`, `gem`, versioned `bunx`).

Example (`plugins/typescript-lsp/package.json`):
```json
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Install only the language servers you need:
>
> Each installing plugin has an **Auto-install language server** option (`auto_install`, default
> on). Turn it off in `/config` to stop session-start installs and updates for that plugin.
> For plugins that run through `code` (clangd, kotlin, dart, and the others that download a
> server the first time it starts), turning it off also stops those downloads, so the plugin
> uses only a server that is already installed or on `PATH`.

### Plugin management

Expand Down
5 changes: 4 additions & 1 deletion packages/lsp/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export const MyServer: LSPServerInfo = {

## Auto-Download Pattern (Kotlin Example)

For servers requiring runtime dependencies:
For servers requiring runtime dependencies. Call `autoInstallDisabled('<id>')` from
`./utils` right before any download or install, after the PATH and cache lookups:
it returns true when `CODE_LSP_AUTO_INSTALL` is false/0/no/off, which the plugins
set from their `auto_install` option.

```typescript
const KOTLIN_RUNTIME_DEPS = {
Expand Down
4 changes: 3 additions & 1 deletion packages/lsp/src/server/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fs from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import process from 'node:process'
import { attachLSPProcessHandlers, log, nearestRoot } from './utils'
import { attachLSPProcessHandlers, autoInstallDisabled, log, nearestRoot } from './utils'

const ASTRO_RUNTIME_DEPS = {
astroLanguageServer: {
Expand Down Expand Up @@ -63,6 +63,8 @@ async function setupAstroDependencies(): Promise<{
needsInstall = true
}

if (needsInstall && autoInstallDisabled('astro')) { needsInstall = false }

if (needsInstall) {
log.info('Installing Astro Language Server')
try {
Expand Down
4 changes: 3 additions & 1 deletion packages/lsp/src/server/bash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fs from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import process from 'node:process'
import { attachLSPProcessHandlers, log } from './utils'
import { attachLSPProcessHandlers, autoInstallDisabled, log } from './utils'

const BASH_RUNTIME_DEPS = {
bashLanguageServer: {
Expand Down Expand Up @@ -48,6 +48,8 @@ async function setupBashDependencies(): Promise<string | undefined> {
needsInstall = true
}

if (needsInstall && autoInstallDisabled('bash')) { needsInstall = false }

if (needsInstall) {
log.info('Installing Bash Language Server')
try {
Expand Down
3 changes: 2 additions & 1 deletion packages/lsp/src/server/biome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { spawn } from 'node:child_process'
import fs from 'node:fs/promises'
import path from 'node:path'
import process from 'node:process'
import { attachLSPProcessHandlers, log, nearestRoot } from './utils'
import { attachLSPProcessHandlers, autoInstallDisabled, log, nearestRoot } from './utils'

/** @biomejs/biome version installed by the bunx fallback. */
export const BIOME_VERSION = '2.6.2'
Expand Down Expand Up @@ -81,6 +81,7 @@ export const BiomeServer: LSPServerInfo = {
log.warn({ root }, 'Biome not found. Install with: npm install @biomejs/biome')
return undefined
}
if (autoInstallDisabled('biome')) { return undefined }
const proc = spawn(bunx, [`@biomejs/biome@${BIOME_VERSION}`, 'lsp-proxy', '--stdio'], {
cwd: root,
env: { ...process.env, BUN_BE_BUN: '1' },
Expand Down
3 changes: 2 additions & 1 deletion packages/lsp/src/server/clangd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import fs from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import process from 'node:process'
import { attachLSPProcessHandlers, downloadFile, extractZip, log, nearestRoot } from './utils'
import { attachLSPProcessHandlers, autoInstallDisabled, downloadFile, extractZip, log, nearestRoot } from './utils'

function getClangdResourcesDir(): string {
return path.join(os.homedir(), '.cache', 'dora', 'clangd-lsp')
Expand Down Expand Up @@ -55,6 +55,7 @@ export const ClangdServer: LSPServerInfo = {
}

// Download from GitHub releases
if (autoInstallDisabled('clangd')) { return undefined }
log.info('Downloading clangd from GitHub releases')
await fs.mkdir(resourcesDir, { recursive: true })

Expand Down
4 changes: 3 additions & 1 deletion packages/lsp/src/server/csharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import fs from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import process from 'node:process'
import { attachLSPProcessHandlers, log, nearestRoot } from './utils'
import { attachLSPProcessHandlers, autoInstallDisabled, log, nearestRoot } from './utils'

function getCsharpResourcesDir(): string {
return path.join(os.homedir(), '.cache', 'dora', 'csharp-lsp')
Expand Down Expand Up @@ -37,6 +37,8 @@ export const CsharpServer: LSPServerInfo = {
return undefined
}

if (autoInstallDisabled('csharp')) { return undefined }

log.info('Installing csharp-ls via dotnet tool')
await fs.mkdir(resourcesDir, { recursive: true })

Expand Down
3 changes: 2 additions & 1 deletion packages/lsp/src/server/dart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os from 'node:os'
import path from 'node:path'
import process from 'node:process'
import { attachLSPProcessHandlers, downloadAndExtract, findRunnableBin, getPlatformId, log, nearestRoot } from './utils'
import { attachLSPProcessHandlers, autoInstallDisabled, downloadAndExtract, findRunnableBin, getPlatformId, log, nearestRoot } from './utils'

/**
* Dart SDK runtime dependency configuration
Expand Down Expand Up @@ -52,7 +52,7 @@
* Setup Dart runtime dependencies
* Downloads Dart SDK if not available and dart is not in PATH
*/
async function setupDartDependencies(platformId: PlatformId): Promise<string | undefined> {

Check failure on line 55 in packages/lsp/src/server/dart.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=pleaseai_code-intelligence&issues=AaIFyDIbwEz4wE4bnI7v&open=AaIFyDIbwEz4wE4bnI7v&pullRequest=156
const config = DART_RUNTIME_DEPS.platforms[platformId]

if (!config) {
Expand All @@ -78,6 +78,7 @@
}

// Dart not found, download it
if (autoInstallDisabled('dart')) { return undefined }
log.info({ version: DART_RUNTIME_DEPS.version, platformId }, 'Downloading Dart SDK')
try {
await downloadAndExtract(config.url, resourcesDir)
Expand Down
4 changes: 3 additions & 1 deletion packages/lsp/src/server/dockerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fs from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import process from 'node:process'
import { attachLSPProcessHandlers, log } from './utils'
import { attachLSPProcessHandlers, autoInstallDisabled, log } from './utils'

const DOCKERFILE_RUNTIME_DEPS = {
dockerfileLanguageServer: {
Expand Down Expand Up @@ -48,6 +48,8 @@ async function setupDockerfileDependencies(): Promise<string | undefined> {
needsInstall = true
}

if (needsInstall && autoInstallDisabled('dockerfile')) { needsInstall = false }

if (needsInstall) {
log.info('Installing Dockerfile Language Server')
try {
Expand Down
4 changes: 3 additions & 1 deletion packages/lsp/src/server/elixir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import fs from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import process from 'node:process'
import { attachLSPProcessHandlers, downloadFile, extractZip, log, nearestRoot } from './utils'
import { attachLSPProcessHandlers, autoInstallDisabled, downloadFile, extractZip, log, nearestRoot } from './utils'

function getElixirLsResourcesDir(): string {
return path.join(os.homedir(), '.cache', 'dora', 'elixir-lsp')
Expand Down Expand Up @@ -57,6 +57,8 @@ export const ElixirLsServer: LSPServerInfo = {
return undefined
}

if (autoInstallDisabled('elixir-ls')) { return undefined }

log.info('Downloading and building ElixirLS')
await fs.mkdir(resourcesDir, { recursive: true })

Expand Down
4 changes: 3 additions & 1 deletion packages/lsp/src/server/eslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import path from 'node:path'
import process from 'node:process'
import { pipeline } from 'node:stream/promises'
import { attachLSPProcessHandlers, log, nearestRoot } from './utils'
import { attachLSPProcessHandlers, autoInstallDisabled, log, nearestRoot } from './utils'

function getEslintResourcesDir(): string {
return path.join(os.homedir(), '.cache', 'dora', 'eslint-lsp')
}

async function setupEslintDependencies(): Promise<string | undefined> {

Check failure on line 20 in packages/lsp/src/server/eslint.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=pleaseai_code-intelligence&issues=AaIFyDJHwEz4wE4bnI7x&open=AaIFyDJHwEz4wE4bnI7x&pullRequest=156
const resourcesDir = getEslintResourcesDir()
const vscodeEslintDir = path.join(resourcesDir, 'vscode-eslint')
const serverPath = path.join(vscodeEslintDir, 'server', 'out', 'eslintServer.js')
Expand All @@ -37,6 +37,8 @@
}
}

if (autoInstallDisabled('eslint')) { return undefined }

log.info('Downloading and building VS Code ESLint server...')

try {
Expand Down
4 changes: 3 additions & 1 deletion packages/lsp/src/server/fsharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import fs from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import process from 'node:process'
import { attachLSPProcessHandlers, log, nearestRoot } from './utils'
import { attachLSPProcessHandlers, autoInstallDisabled, log, nearestRoot } from './utils'

function getFsharpResourcesDir(): string {
return path.join(os.homedir(), '.cache', 'dora', 'fsharp-lsp')
Expand Down Expand Up @@ -37,6 +37,8 @@ export const FsharpServer: LSPServerInfo = {
return undefined
}

if (autoInstallDisabled('fsharp')) { return undefined }

log.info('Installing fsautocomplete via dotnet tool')
await fs.mkdir(resourcesDir, { recursive: true })

Expand Down
3 changes: 3 additions & 0 deletions packages/lsp/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ export type { LSPServerHandle, LSPServerInfo, PlatformId, RootFunction } from '.
// Re-export utilities
export {
attachLSPProcessHandlers,
AUTO_INSTALL_ENV,
autoInstallDisabled,
downloadAndExtract,
downloadFile,
extractZip,
getPlatformId,
isAutoInstallEnabled,
log,
nearestRoot,
} from './utils'
Expand Down
3 changes: 2 additions & 1 deletion packages/lsp/src/server/jdtls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import fs from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import process from 'node:process'
import { attachLSPProcessHandlers, downloadFile, log, nearestRoot } from './utils'
import { attachLSPProcessHandlers, autoInstallDisabled, downloadFile, log, nearestRoot } from './utils'

function getJdtlsResourcesDir(): string {
return path.join(os.homedir(), '.cache', 'dora', 'jdtls-lsp')
Expand Down Expand Up @@ -56,6 +56,7 @@ export const JdtlsServer: LSPServerInfo = {
await fs.access(launcherDir)
}
catch {
if (autoInstallDisabled('jdtls')) { return undefined }
log.info('Downloading JDTLS from Eclipse')
await fs.mkdir(distPath, { recursive: true })

Expand Down
4 changes: 3 additions & 1 deletion packages/lsp/src/server/kotlin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import fs from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import process from 'node:process'
import { attachLSPProcessHandlers, downloadAndExtract, getPlatformId, log, nearestRoot } from './utils'
import { attachLSPProcessHandlers, autoInstallDisabled, downloadAndExtract, getPlatformId, log, nearestRoot } from './utils'

/**
* Kotlin Language Server runtime dependency configuration
Expand Down Expand Up @@ -91,6 +91,7 @@ async function setupKotlinDependencies(platformId: PlatformId): Promise<{
}

// Java not found, download it
if (autoInstallDisabled('kotlin')) { return undefined }
log.info({ platformId }, 'Downloading Java 21')
try {
await downloadAndExtract(javaConfig.url, javaDir)
Expand Down Expand Up @@ -141,6 +142,7 @@ async function setupKotlinDependencies(platformId: PlatformId): Promise<{
}

// Kotlin LSP not found, download it
if (autoInstallDisabled('kotlin')) { return undefined }
log.info('Downloading Kotlin Language Server')
try {
await downloadAndExtract(KOTLIN_RUNTIME_DEPS.kotlinLsp.url, resourcesDir)
Expand Down
Loading