| 6 | import { ExecutableOptions } from 'vscode-languageclient/node'; |
| 7 | |
| 8 | export function getServerPath(context: vscode.ExtensionContext): string { |
| 9 | console.log('Dada LSP: Extension path is', context.extensionPath); |
| 10 | |
| 11 | // 1. Check user configuration first |
| 12 | const config = vscode.workspace.getConfiguration('dada'); |
| 13 | const configuredPath = config.get<string>('serverPath'); |
| 14 | console.log('Dada LSP: Configured server path from settings:', configuredPath); |
| 15 | if (configuredPath && fs.existsSync(configuredPath)) { |
| 16 | console.log('Dada LSP: Using configured server path:', configuredPath); |
| 17 | return configuredPath; |
| 18 | } |
| 19 | |
| 20 | // 2. Try to use bundled binary based on platform |
| 21 | const platform = os.platform(); |
| 22 | const arch = os.arch(); |
| 23 | |
| 24 | let binaryName = 'dada-lsp-server'; |
| 25 | if (platform === 'win32') { |
| 26 | binaryName += '.exe'; |
| 27 | } |
| 28 | |
| 29 | console.log('Dada LSP: extension path', context.extensionPath); |
| 30 | |
| 31 | const platformDir = `${platform === 'win32' ? 'win32' : platform === 'darwin' ? 'darwin' : 'linux'}-${arch === 'x64' ? 'x64' : arch === 'arm64' ? 'arm64' : 'x64'}`; |
| 32 | const bundledPath = path.join(context.extensionPath, 'bin', platformDir, binaryName); |
| 33 | console.log('Dada LSP: Calculated bundled server path:', bundledPath); |
| 34 | |
| 35 | if (fs.existsSync(bundledPath)) { |
| 36 | console.log('Dada LSP: Bundled server binary exists'); |
| 37 | // Make sure the binary is executable on Unix systems |
| 38 | if (platform !== 'win32') { |
| 39 | try { |
| 40 | fs.chmodSync(bundledPath, '755'); |
| 41 | } catch (e) { |
| 42 | console.error('Failed to make server binary executable:', e); |
| 43 | } |
| 44 | } |
| 45 | console.log('Dada LSP: Using bundled server path:', bundledPath); |
| 46 | return bundledPath; |
| 47 | } else { |
| 48 | console.log('Dada LSP: Bundled server binary does not exist at path:', bundledPath); |
| 49 | } |
| 50 | |
| 51 | // 3. Development fallback: try to use cargo run |
| 52 | try { |
| 53 | // Check if we're in a development environment with Cargo available |
| 54 | child_process.execSync('cargo --version', { stdio: 'ignore' }); |
| 55 | |
| 56 | // Return a special marker that tells the extension to use cargo run |
| 57 | console.log('Dada LSP: Using cargo run for development'); |
| 58 | return 'USE_CARGO_RUN'; |
| 59 | } catch (e) { |
| 60 | console.log('Dada LSP: Cargo not available for development fallback'); |
| 61 | // Cargo not available |
| 62 | } |
| 63 | |
| 64 | // 4. If all else fails, assume it's in PATH |
| 65 | console.log('Dada LSP: Falling back to binary in PATH:', binaryName); |