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

Sign up
Appearance settings

Commit 2e70114

Browse files
Merge pull request #7 from arduino/atl-804--custom-debug-config
ATL-804: Support for custom debug config.
2 parents acfc67f + c6a343d commit 2e70114

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"dependencies": {
4242
"@types/deep-equal": "^1.0.1",
4343
"deep-equal": "^2.0.3",
44+
"deepmerge": "^4.2.2",
4445
"path": "^0.12.7",
4546
"vscode-languageclient": "^6.1.3",
4647
"web-request": "^1.0.7"

‎src/extension.ts‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import {stat} from 'fs';
2-
import {basename} from 'path';
1+
import *asfs from 'fs';
2+
import *aspath from 'path';
33
import { promisify } from 'util';
44
import { spawnSync } from 'child_process';
55
import deepEqual from 'deep-equal';
66
import WebRequest from 'web-request';
7+
import deepmerge from 'deepmerge';
78
import vscode, { ExtensionContext } from 'vscode';
89
import { LanguageClient, CloseAction, ErrorAction, InitializeError, Message, RevealOutputChannelOn } from 'vscode-languageclient';
910

@@ -80,7 +81,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
8081
if (!rawStdout) {
8182
if (rawStdErr) {
8283
if (rawStdErr.indexOf('compiled sketch not found in') !== -1) {
83-
vscode.window.showErrorMessage(`Sketch '${basename(config.sketchPath)}' was not compiled. Please compile the sketch and start debugging again.`);
84+
vscode.window.showErrorMessage(`Sketch '${path.basename(config.sketchPath)}' was not compiled. Please compile the sketch and start debugging again.`);
8485
} else {
8586
vscode.window.showErrorMessage(rawStdErr);
8687
}
@@ -95,7 +96,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
9596
if (!info) {
9697
return false;
9798
}
98-
const debugConfig = {
99+
const defaultDebugConfig = {
99100
cwd: '${workspaceRoot}',
100101
name: 'Arduino',
101102
request: 'launch',
@@ -108,18 +109,26 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
108109
info.server_configuration.script
109110
]
110111
};
112+
113+
let customDebugConfig = {};
114+
try {
115+
const raw = await promisify(fs.readFile)(path.join(config.sketchPath, 'debug_custom.json'), { encoding: 'utf8' });
116+
customDebugConfig = JSON.parse(raw);
117+
} catch { }
118+
const mergedDebugConfig = deepmerge(defaultDebugConfig, customDebugConfig);
119+
111120
// Create the `launch.json` if it does not exist. Otherwise, update the existing.
112121
const configuration = vscode.workspace.getConfiguration();
113122
const launchConfig = {
114123
version: '0.2.0',
115124
'configurations': [
116125
{
117-
...debugConfig
126+
...mergedDebugConfig
118127
}
119128
]
120129
};
121130
await configuration.update('launch', launchConfig, false);
122-
return vscode.debug.startDebugging(undefined, debugConfig);
131+
return vscode.debug.startDebugging(undefined, mergedDebugConfig);
123132
}
124133

125134
async function startLanguageServer(context: ExtensionContext, config: LanguageServerConfig): Promise<void> {
@@ -162,7 +171,7 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
162171
let logPath: string | undefined = undefined;
163172
if (typeof log === 'string') {
164173
try {
165-
const stats = await promisify(stat)(log);
174+
const stats = await promisify(fs.stat)(log);
166175
if (stats.isDirectory()) {
167176
logPath = log;
168177
}

‎yarn.lock‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,11 @@ deep-equal@^2.0.3:
10501050
which-collection "^1.0.1"
10511051
which-typed-array "^1.1.2"
10521052

1053+
deepmerge@^4.2.2:
1054+
version "4.2.2"
1055+
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"
1056+
integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==
1057+
10531058
define-properties@^1.1.2, define-properties@^1.1.3:
10541059
version "1.1.3"
10551060
resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /