Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fs][plugin] fix #6661: map editor icon paths to external URIs #6664

Merged
merged 1 commit into from
Dec 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/filesystem/src/node/download/file-download-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

// tslint:disable:no-any

import * as url from 'url';
import { injectable, inject, named } from 'inversify';
import { json } from 'body-parser';
// tslint:disable-next-line:no-implicit-dependencies
import { Application, Router } from 'express';
import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application';
import { FileUri } from '@theia/core/lib/node/file-uri';
import { FileDownloadHandler } from './file-download-handler';

@injectable()
Expand Down Expand Up @@ -48,6 +50,15 @@ export class FileDownloadEndpoint implements BackendApplicationContribution {
// Content-Type: application/json
app.use(json());
app.use(FileDownloadEndpoint.PATH, router);
app.get('/file', (request, response) => {
const uri = url.parse(request.url).query;
if (!uri) {
response.status(400).send('invalid uri');
return;
}
const fsPath = FileUri.fsPath(decodeURIComponent(uri));
response.sendFile(fsPath);
});
}

}
33 changes: 32 additions & 1 deletion packages/plugin-ext/src/main/browser/text-editors-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import URI from 'vscode-uri';
import {
TextEditorsMain,
MAIN_RPC_CONTEXT,
Expand All @@ -25,6 +26,7 @@ import {
ApplyEditsOptions,
UndoStopOptions,
DecorationRenderOptions,
ThemeDecorationInstanceRenderOptions,
DecorationOptions,
WorkspaceEditDto
} from '../../common/plugin-api-rpc';
Expand All @@ -37,18 +39,21 @@ import { disposed } from '../../common/errors';
import { toMonacoWorkspaceEdit } from './languages-main';
import { MonacoBulkEditService } from '@theia/monaco/lib/browser/monaco-bulk-edit-service';
import { MonacoEditorService } from '@theia/monaco/lib/browser/monaco-editor-service';
import { theiaUritoUriComponents, UriComponents } from '../../common/uri-components';
import { Endpoint } from '@theia/core/lib/browser/endpoint';

export class TextEditorsMainImpl implements TextEditorsMain, Disposable {

private readonly proxy: TextEditorsExt;
private readonly toDispose = new DisposableCollection();
private readonly editorsToDispose = new Map<string, DisposableCollection>();
private readonly fileEndpoint = new Endpoint({ path: 'file' }).getRestUrl();

constructor(
private readonly editorsAndDocuments: EditorsAndDocumentsMain,
rpc: RPCProtocol,
private readonly bulkEditService: MonacoBulkEditService,
private readonly monacoEditorService: MonacoEditorService
private readonly monacoEditorService: MonacoEditorService,
) {
this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.TEXT_EDITORS_EXT);
this.toDispose.push(editorsAndDocuments);
Expand Down Expand Up @@ -127,10 +132,36 @@ export class TextEditorsMainImpl implements TextEditorsMain, Disposable {
}

$registerTextEditorDecorationType(key: string, options: DecorationRenderOptions): void {
this.injectRemoteUris(options);
this.monacoEditorService.registerDecorationType(key, options);
this.toDispose.push(Disposable.create(() => this.$removeTextEditorDecorationType(key)));
}

protected injectRemoteUris(options: DecorationRenderOptions | ThemeDecorationInstanceRenderOptions): void {
if (options.before) {
options.before.contentIconPath = this.toRemoteUri(options.before.contentIconPath);
}
if (options.after) {
options.after.contentIconPath = this.toRemoteUri(options.after.contentIconPath);
}
if ('gutterIconPath' in options) {
options.gutterIconPath = this.toRemoteUri(options.gutterIconPath);
}
if ('dark' in options && options.dark) {
this.injectRemoteUris(options.dark);
}
if ('light' in options && options.light) {
this.injectRemoteUris(options.light);
}
}

protected toRemoteUri(uri?: UriComponents): UriComponents | undefined {
if (uri && uri.scheme === 'file') {
return theiaUritoUriComponents(this.fileEndpoint.withQuery(URI.revive(uri).toString()));
}
return uri;
}

$removeTextEditorDecorationType(key: string): void {
this.monacoEditorService.removeDecorationType(key);
}
Expand Down