Skip to content

Commit a4c7900

Browse files
committed
Add support for "ide.get_pio_project_dirs()" command (PIO Home)
1 parent 68bce30 commit a4c7900

File tree

1 file changed

+53
-38
lines changed

1 file changed

+53
-38
lines changed

src/home.js

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import * as pioNodeHelpers from 'platformio-node-helpers';
1010

1111
import { IS_OSX } from './constants';
12+
import ProjectObservable from './project/observable';
1213
import crypto from 'crypto';
1314
import { extension } from './main';
1415
import { notifyError } from './utils';
@@ -97,44 +98,7 @@ export default class PIOHome {
9798
await pioNodeHelpers.home.ensureServerStarted({
9899
port: extension.getSetting('pioHomeServerHttpPort'),
99100
host: extension.getSetting('pioHomeServerHttpHost'),
100-
onIDECommand: async (command, params) => {
101-
if (command === 'open_project') {
102-
if (extension.projectObservable) {
103-
extension.projectObservable.saveProjectStateItem(
104-
vscode.Uri.file(params).fsPath,
105-
'activeEnv',
106-
undefined
107-
);
108-
}
109-
this.disposePanel();
110-
if (vscode.workspace.workspaceFolders) {
111-
vscode.workspace.updateWorkspaceFolders(
112-
vscode.workspace.workspaceFolders.length,
113-
null,
114-
{ uri: vscode.Uri.file(params) }
115-
);
116-
} else {
117-
vscode.commands.executeCommand(
118-
'vscode.openFolder',
119-
vscode.Uri.file(params)
120-
);
121-
}
122-
vscode.commands.executeCommand('workbench.view.explorer');
123-
} else if (command === 'open_text_document') {
124-
const editor = await vscode.window.showTextDocument(
125-
vscode.Uri.file(params.path)
126-
);
127-
const gotoPosition = new vscode.Position(
128-
(params.line || 1) - 1,
129-
(params.column || 1) - 1
130-
);
131-
editor.selection = new vscode.Selection(gotoPosition, gotoPosition);
132-
editor.revealRange(
133-
new vscode.Range(gotoPosition, gotoPosition),
134-
vscode.TextEditorRevealType.InCenter
135-
);
136-
}
137-
},
101+
onIDECommand: await this.onIDECommand.bind(this),
138102
});
139103
const theme = this.getTheme();
140104
const iframeId =
@@ -174,6 +138,57 @@ export default class PIOHome {
174138
`;
175139
}
176140

141+
async onIDECommand(command, params) {
142+
switch (command) {
143+
case 'open_project':
144+
return this.onOpenProjectCommand(params);
145+
case 'open_text_document':
146+
return await this.onOpenTextDocumentCommand(params);
147+
case 'get_pio_project_dirs':
148+
return this.onGetPIOProjectDirs();
149+
}
150+
}
151+
152+
onOpenProjectCommand(params) {
153+
if (extension.projectObservable) {
154+
extension.projectObservable.saveProjectStateItem(
155+
vscode.Uri.file(params).fsPath,
156+
'activeEnv',
157+
undefined
158+
);
159+
}
160+
this.disposePanel();
161+
if (vscode.workspace.workspaceFolders) {
162+
vscode.workspace.updateWorkspaceFolders(
163+
vscode.workspace.workspaceFolders.length,
164+
null,
165+
{ uri: vscode.Uri.file(params) }
166+
);
167+
} else {
168+
vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.file(params));
169+
}
170+
vscode.commands.executeCommand('workbench.view.explorer');
171+
return true;
172+
}
173+
174+
async onOpenTextDocumentCommand(params) {
175+
const editor = await vscode.window.showTextDocument(vscode.Uri.file(params.path));
176+
const gotoPosition = new vscode.Position(
177+
(params.line || 1) - 1,
178+
(params.column || 1) - 1
179+
);
180+
editor.selection = new vscode.Selection(gotoPosition, gotoPosition);
181+
editor.revealRange(
182+
new vscode.Range(gotoPosition, gotoPosition),
183+
vscode.TextEditorRevealType.InCenter
184+
);
185+
return true;
186+
}
187+
188+
onGetPIOProjectDirs() {
189+
return ProjectObservable.getPIOProjectDirs();
190+
}
191+
177192
onPanelDisposed() {
178193
this._currentPanel = undefined;
179194
}

0 commit comments

Comments
 (0)