From 328b54e82d165c71247b7dc0c9673cb7e833888a Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Tue, 15 Dec 2020 13:51:33 +0100 Subject: [PATCH 1/3] Enabled syntax coloring for C++ files. Signed-off-by: Akos Kitta --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 270cf44..99b605e 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,11 @@ "ino" ], "extensions": [ - ".ino" + ".ino", + ".c", + ".cpp", + ".h", + ".hpp" ], "configuration": "./languages/ino.language-configuration.json" } From 0f89ca5af152961767ac5985ac9ffa748d7114aa Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Tue, 15 Dec 2020 13:52:54 +0100 Subject: [PATCH 2/3] Removed obsolete compilation DB param. - Adjusted the document selector to trigger LS start with C++ and header files. - Enabled `log` by default. Signed-off-by: Akos Kitta --- src/extension.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 172f39f..12bf647 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -9,10 +9,6 @@ interface LanguageServerConfig { readonly lsPath: string; readonly cliPath: string; readonly clangdPath: string; - /** - * Filesystem path pointing to the folder that contains the `compile_commands.json` file. - */ - readonly compileCommandsPath?: string; readonly board: { readonly fqbn: string; readonly name?: string; @@ -144,14 +140,11 @@ function buildLanguageClient(config: LanguageServerConfig): LanguageClient { if (!serverTraceChannel) { serverTraceChannel = vscode.window.createOutputChannel('Arduino Language Server (trace)'); } - const { lsPath: command, clangdPath, cliPath, board, flags, env, compileCommandsPath } = config; + const { lsPath: command, clangdPath, cliPath, board, flags, env } = config; const args = ['-clangd', clangdPath, '-cli', cliPath, '-fqbn', board.fqbn]; if (board.name) { args.push('-board-name', board.name); } - if (compileCommandsPath) { - args.push('-compile-commands-dir', compileCommandsPath); - } if (flags && flags.length) { args.push(...flags); } @@ -165,7 +158,7 @@ function buildLanguageClient(config: LanguageServerConfig): LanguageClient { }, { initializationOptions: {}, - documentSelector: ['ino'], + documentSelector: ['ino', 'c', 'cpp', 'h', 'hpp'], uriConverters: { code2Protocol: (uri: vscode.Uri): string => (uri.scheme ? uri : uri.with({ scheme: 'file' })).toString(), protocol2Code: (uri: string) => vscode.Uri.parse(uri) From 317475db156ebc55919aa3a9383cf1e99d1d29e2 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Tue, 15 Dec 2020 14:36:03 +0100 Subject: [PATCH 3/3] Enable `log` when requested by the IDE. - Can modify `logpath` if requested. Signed-off-by: Akos Kitta --- src/extension.ts | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 12bf647..746ca3f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,4 +1,6 @@ -import { posix } from 'path'; +import { stat } from 'fs'; +import { basename } from 'path'; +import { promisify } from 'util'; import { spawnSync } from 'child_process'; import deepEqual from 'deep-equal'; import WebRequest from 'web-request'; @@ -13,6 +15,13 @@ interface LanguageServerConfig { readonly fqbn: string; readonly name?: string; } + /** + * `true` if the LS should generate log files into the default location. The default location is `cwd` of the process. It's very often the same + * as the workspace root of the IDE, aka the sketch folder. + * When it is a string, it is the folder where the log files should be generated. If the path is invalid (does not exist, not a folder), + * the log files will be generated into the default location. + */ + readonly log?: boolean | string; readonly env?: any; readonly flags?: string[]; } @@ -71,7 +80,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise { if (!serverOutputChannel) { serverOutputChannel = vscode.window.createOutputChannel('Arduino Language Server'); } if (!serverTraceChannel) { serverTraceChannel = vscode.window.createOutputChannel('Arduino Language Server (trace)'); } - const { lsPath: command, clangdPath, cliPath, board, flags, env } = config; + const { lsPath: command, clangdPath, cliPath, board, flags, env, log } = config; const args = ['-clangd', clangdPath, '-cli', cliPath, '-fqbn', board.fqbn]; if (board.name) { args.push('-board-name', board.name); @@ -148,6 +157,21 @@ function buildLanguageClient(config: LanguageServerConfig): LanguageClient { if (flags && flags.length) { args.push(...flags); } + if (!!log) { + args.push('-log'); + let logPath: string | undefined = undefined; + if (typeof log === 'string') { + try { + const stats = await promisify(stat)(log); + if (stats.isDirectory()) { + logPath = log; + } + } catch { } + } + if (logPath) { + args.push('-logpath', logPath); + } + } return new LanguageClient( 'ino', 'Arduino Language Server',