(selector: DocumentFilter[],
cwd: string, workspaceFolder: WorkspaceFolder | undefined, outputChannel: OutputChannel)
| 52 | } |
| 53 | |
| 54 | private async createClient(selector: DocumentFilter[], |
| 55 | cwd: string, workspaceFolder: WorkspaceFolder | undefined, outputChannel: OutputChannel): Promise<LanguageClient> { |
| 56 | |
| 57 | let client: LanguageClient; |
| 58 | |
| 59 | const debug = this.config.get<boolean>('lsp.debug'); |
| 60 | const useRenvLibPath = this.config.get<boolean>('useRenvLibPath') ?? false; |
| 61 | const rPath = await getRpath() || ''; // TODO: Abort gracefully |
| 62 | if (debug) { |
| 63 | console.log(`R path: ${rPath}`); |
| 64 | } |
| 65 | const use_stdio = this.config.get<boolean>('lsp.use_stdio'); |
| 66 | const env = Object.create(process.env) as NodeJS.ProcessEnv; |
| 67 | env.VSCR_LSP_DEBUG = debug ? 'TRUE' : 'FALSE'; |
| 68 | env.VSCR_LIB_PATHS = getRLibPaths(); |
| 69 | env.VSCR_USE_RENV_LIB_PATH = useRenvLibPath ? 'TRUE' : 'FALSE'; |
| 70 | |
| 71 | const lang = this.config.get<string>('lsp.lang'); |
| 72 | if (lang !== '') { |
| 73 | env.LANG = lang; |
| 74 | } else if (env.LANG === undefined) { |
| 75 | env.LANG = 'en_US.UTF-8'; |
| 76 | } |
| 77 | |
| 78 | if (debug) { |
| 79 | // eslint-disable-next-line @typescript-eslint/restrict-template-expressions |
| 80 | console.log(`LANG: ${env.LANG}`); |
| 81 | } |
| 82 | |
| 83 | const rScriptPath = extensionContext.asAbsolutePath('R/languageServer.R'); |
| 84 | const options = { cwd: cwd, env: env }; |
| 85 | const args = (this.config.get<string[]>('lsp.args')?.map(substituteVariables) ?? []).concat( |
| 86 | '--silent', |
| 87 | '--no-echo', |
| 88 | '--no-save', |
| 89 | '--no-restore', |
| 90 | '-e', |
| 91 | 'base::source(base::commandArgs(TRUE))', |
| 92 | '--args', |
| 93 | rScriptPath |
| 94 | ); |
| 95 | |
| 96 | const tcpServerOptions = () => new Promise<DisposableProcess | StreamInfo>((resolve, reject) => { |
| 97 | // Use a TCP socket because of problems with blocking STDIO |
| 98 | const server = net.createServer(socket => { |
| 99 | // 'connection' listener |
| 100 | console.log('R process connected'); |
| 101 | socket.on('end', () => { |
| 102 | console.log('R process disconnected'); |
| 103 | }); |
| 104 | socket.on('error', (e: Error) => { |
| 105 | console.log(`R process error: ${e.message}`); |
| 106 | reject(e); |
| 107 | }); |
| 108 | server.close(); |
| 109 | resolve({ reader: socket, writer: socket }); |
| 110 | }); |
| 111 | // Listen on random port |
no test coverage detected