Skip to content

Commit acbd98d

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
Fixed workspace variable resolver.
Fall back to the current sketch, if `currentWidget` points to a file outside of the workspace. Closes: #46 Signed-off-by: Akos Kitta <[email protected]>
1 parent 22e02e1 commit acbd98d

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ import { ArchiveSketch } from './contributions/archive-sketch';
143143
import { OutputToolbarContribution as TheiaOutputToolbarContribution } from '@theia/output/lib/browser/output-toolbar-contribution';
144144
import { OutputToolbarContribution } from './theia/output/output-toolbar-contribution';
145145
import { AddZipLibrary } from './contributions/add-zip-library';
146+
import { WorkspaceVariableContribution as TheiaWorkspaceVariableContribution } from '@theia/workspace/lib/browser/workspace-variable-contribution';
147+
import { WorkspaceVariableContribution } from './theia/workspace/workspace-variable-contribution';
146148

147149
const ElementQueries = require('css-element-queries/src/ElementQueries');
148150

@@ -257,6 +259,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
257259

258260
bind(WorkspaceService).toSelf().inSingletonScope();
259261
rebind(TheiaWorkspaceService).toService(WorkspaceService);
262+
bind(WorkspaceVariableContribution).toSelf().inSingletonScope();
263+
rebind(TheiaWorkspaceVariableContribution).toService(WorkspaceVariableContribution);
260264

261265
// Customizing default Theia layout based on the editor mode: `pro-mode` or `classic`.
262266
bind(EditorMode).toSelf().inSingletonScope();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { inject, injectable, postConstruct } from 'inversify';
2+
import URI from '@theia/core/lib/common/uri';
3+
import { WorkspaceVariableContribution as TheiaWorkspaceVariableContribution } from '@theia/workspace/lib/browser/workspace-variable-contribution';
4+
import { Sketch } from '../../../common/protocol';
5+
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
6+
7+
@injectable()
8+
export class WorkspaceVariableContribution extends TheiaWorkspaceVariableContribution {
9+
10+
@inject(SketchesServiceClientImpl)
11+
protected readonly sketchesServiceClient: SketchesServiceClientImpl;
12+
13+
protected currentSketch?: Sketch;
14+
15+
@postConstruct()
16+
protected init(): void {
17+
this.sketchesServiceClient.currentSketch().then().then(sketch => this.currentSketch = sketch);
18+
}
19+
20+
getResourceUri(): URI | undefined {
21+
const resourceUri = super.getResourceUri();
22+
// https://github.com/arduino/arduino-ide/issues/46
23+
// `currentWidget` can be an editor representing a file outside of the workspace. The current sketch should be a fallback.
24+
if (!resourceUri && this.currentSketch?.uri) {
25+
return new URI(this.currentSketch.uri);
26+
}
27+
return resourceUri;
28+
}
29+
}

0 commit comments

Comments
 (0)