Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit acfc67f

Browse filesBrowse files
authored
Merge pull request #6 from arduino/ls-integration
Integration with the latest Arduino LS
2 parents e4ef8ed + 317475d commit acfc67f
Copy full SHA for acfc67f

File tree

Expand file treeCollapse file tree

2 files changed

+35
-14
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+35
-14
lines changed

‎package.json

Copy file name to clipboardExpand all lines: package.json
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@
8080
"ino"
8181
],
8282
"extensions": [
83-
".ino"
83+
".ino",
84+
".c",
85+
".cpp",
86+
".h",
87+
".hpp"
8488
],
8589
"configuration": "./languages/ino.language-configuration.json"
8690
}

‎src/extension.ts

Copy file name to clipboardExpand all lines: src/extension.ts
+30-13Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { posix } from 'path';
1+
import { stat } from 'fs';
2+
import { basename } from 'path';
3+
import { promisify } from 'util';
24
import { spawnSync } from 'child_process';
35
import deepEqual from 'deep-equal';
46
import WebRequest from 'web-request';
@@ -9,14 +11,17 @@ interface LanguageServerConfig {
911
readonly lsPath: string;
1012
readonly cliPath: string;
1113
readonly clangdPath: string;
12-
/**
13-
* Filesystem path pointing to the folder that contains the `compile_commands.json` file.
14-
*/
15-
readonly compileCommandsPath?: string;
1614
readonly board: {
1715
readonly fqbn: string;
1816
readonly name?: string;
1917
}
18+
/**
19+
* `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
20+
* as the workspace root of the IDE, aka the sketch folder.
21+
* 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),
22+
* the log files will be generated into the default location.
23+
*/
24+
readonly log?: boolean | string;
2025
readonly env?: any;
2126
readonly flags?: string[];
2227
}
@@ -75,7 +80,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
7580
if (!rawStdout) {
7681
if (rawStdErr) {
7782
if (rawStdErr.indexOf('compiled sketch not found in') !== -1) {
78-
vscode.window.showErrorMessage(`Sketch '${posix.basename(config.sketchPath)}' was not compiled. Please compile the sketch and start debugging again.`);
83+
vscode.window.showErrorMessage(`Sketch '${basename(config.sketchPath)}' was not compiled. Please compile the sketch and start debugging again.`);
7984
} else {
8085
vscode.window.showErrorMessage(rawStdErr);
8186
}
@@ -129,32 +134,44 @@ async function startLanguageServer(context: ExtensionContext, config: LanguageSe
129134
}
130135
if (!languageClient || !deepEqual(latestConfig, config)) {
131136
latestConfig = config;
132-
languageClient = buildLanguageClient(config);
137+
languageClient = await buildLanguageClient(config);
133138
crashCount = 0;
134139
}
135140

136141
languageServerDisposable = languageClient.start();
137142
context.subscriptions.push(languageServerDisposable);
138143
}
139144

140-
function buildLanguageClient(config: LanguageServerConfig): LanguageClient {
145+
async function buildLanguageClient(config: LanguageServerConfig): Promise<LanguageClient> {
141146
if (!serverOutputChannel) {
142147
serverOutputChannel = vscode.window.createOutputChannel('Arduino Language Server');
143148
}
144149
if (!serverTraceChannel) {
145150
serverTraceChannel = vscode.window.createOutputChannel('Arduino Language Server (trace)');
146151
}
147-
const { lsPath: command, clangdPath, cliPath, board, flags, env, compileCommandsPath } = config;
152+
const { lsPath: command, clangdPath, cliPath, board, flags, env, log } = config;
148153
const args = ['-clangd', clangdPath, '-cli', cliPath, '-fqbn', board.fqbn];
149154
if (board.name) {
150155
args.push('-board-name', board.name);
151156
}
152-
if (compileCommandsPath) {
153-
args.push('-compile-commands-dir', compileCommandsPath);
154-
}
155157
if (flags && flags.length) {
156158
args.push(...flags);
157159
}
160+
if (!!log) {
161+
args.push('-log');
162+
let logPath: string | undefined = undefined;
163+
if (typeof log === 'string') {
164+
try {
165+
const stats = await promisify(stat)(log);
166+
if (stats.isDirectory()) {
167+
logPath = log;
168+
}
169+
} catch { }
170+
}
171+
if (logPath) {
172+
args.push('-logpath', logPath);
173+
}
174+
}
158175
return new LanguageClient(
159176
'ino',
160177
'Arduino Language Server',
@@ -165,7 +182,7 @@ function buildLanguageClient(config: LanguageServerConfig): LanguageClient {
165182
},
166183
{
167184
initializationOptions: {},
168-
documentSelector: ['ino'],
185+
documentSelector: ['ino', 'c', 'cpp', 'h', 'hpp'],
169186
uriConverters: {
170187
code2Protocol: (uri: vscode.Uri): string => (uri.scheme ? uri : uri.with({ scheme: 'file' })).toString(),
171188
protocol2Code: (uri: string) => vscode.Uri.parse(uri)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.