mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-11 21:36:33 +00:00
Fixed workspace variable resolver.
Fall back to the current sketch, if `currentWidget` points to a file outside of the workspace. Closes: arduino/arduino-ide#46 Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
22e02e19b8
commit
acbd98d0f8
@ -143,6 +143,8 @@ import { ArchiveSketch } from './contributions/archive-sketch';
|
||||
import { OutputToolbarContribution as TheiaOutputToolbarContribution } from '@theia/output/lib/browser/output-toolbar-contribution';
|
||||
import { OutputToolbarContribution } from './theia/output/output-toolbar-contribution';
|
||||
import { AddZipLibrary } from './contributions/add-zip-library';
|
||||
import { WorkspaceVariableContribution as TheiaWorkspaceVariableContribution } from '@theia/workspace/lib/browser/workspace-variable-contribution';
|
||||
import { WorkspaceVariableContribution } from './theia/workspace/workspace-variable-contribution';
|
||||
|
||||
const ElementQueries = require('css-element-queries/src/ElementQueries');
|
||||
|
||||
@ -257,6 +259,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||
|
||||
bind(WorkspaceService).toSelf().inSingletonScope();
|
||||
rebind(TheiaWorkspaceService).toService(WorkspaceService);
|
||||
bind(WorkspaceVariableContribution).toSelf().inSingletonScope();
|
||||
rebind(TheiaWorkspaceVariableContribution).toService(WorkspaceVariableContribution);
|
||||
|
||||
// Customizing default Theia layout based on the editor mode: `pro-mode` or `classic`.
|
||||
bind(EditorMode).toSelf().inSingletonScope();
|
||||
|
@ -0,0 +1,29 @@
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user