-
-
Notifications
You must be signed in to change notification settings - Fork 437
/
Copy pathworkspace-variable-contribution.ts
31 lines (27 loc) · 1.2 KB
/
workspace-variable-contribution.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { inject, injectable, postConstruct } from 'inversify';
import URI from '@theia/core/lib/common/uri';
import { WorkspaceVariableContribution as TheiaWorkspaceVariableContribution } from '@theia/workspace/lib/browser/workspace-variable-contribution';
import { Sketch } from '../../../common/protocol';
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
@injectable()
export class WorkspaceVariableContribution extends TheiaWorkspaceVariableContribution {
@inject(SketchesServiceClientImpl)
protected readonly sketchesServiceClient: SketchesServiceClientImpl;
protected currentSketch?: Sketch;
@postConstruct()
protected init(): void {
this.sketchesServiceClient
.currentSketch()
.then()
.then((sketch) => (this.currentSketch = sketch));
}
getResourceUri(): URI | undefined {
const resourceUri = super.getResourceUri();
// https://github.com/arduino/arduino-ide/issues/46
// `currentWidget` can be an editor representing a file outside of the workspace. The current sketch should be a fallback.
if (!resourceUri && this.currentSketch?.uri) {
return new URI(this.currentSketch.uri);
}
return resourceUri;
}
}