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

Integration with the latest Arduino LS #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 17, 2020
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
6 changes: 5 additions & 1 deletion 6 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@
"ino"
],
"extensions": [
".ino"
".ino",
".c",
".cpp",
".h",
".hpp"
],
"configuration": "./languages/ino.language-configuration.json"
}
Expand Down
43 changes: 30 additions & 13 deletions 43 src/extension.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -9,14 +11,17 @@ 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;
}
/**
* `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[];
}
Expand Down Expand Up @@ -75,7 +80,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
if (!rawStdout) {
if (rawStdErr) {
if (rawStdErr.indexOf('compiled sketch not found in') !== -1) {
vscode.window.showErrorMessage(`Sketch '${posix.basename(config.sketchPath)}' was not compiled. Please compile the sketch and start debugging again.`);
vscode.window.showErrorMessage(`Sketch '${basename(config.sketchPath)}' was not compiled. Please compile the sketch and start debugging again.`);
} else {
vscode.window.showErrorMessage(rawStdErr);
}
Expand Down Expand Up @@ -129,32 +134,44 @@ async function startLanguageServer(context: ExtensionContext, config: LanguageSe
}
if (!languageClient || !deepEqual(latestConfig, config)) {
latestConfig = config;
languageClient = buildLanguageClient(config);
languageClient = await buildLanguageClient(config);
crashCount = 0;
}

languageServerDisposable = languageClient.start();
context.subscriptions.push(languageServerDisposable);
}

function buildLanguageClient(config: LanguageServerConfig): LanguageClient {
async function buildLanguageClient(config: LanguageServerConfig): Promise<LanguageClient> {
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, compileCommandsPath } = 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);
}
if (compileCommandsPath) {
args.push('-compile-commands-dir', compileCommandsPath);
}
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',
Expand All @@ -165,7 +182,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)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.