Skip to content

Commit

Permalink
fix #8261: normalize pattern base to support clients on another OS
Browse files Browse the repository at this point in the history
It also removes dependencies to the plugin process code from the main process.

Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Jul 30, 2020
1 parent db34c98 commit 6021f3a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 43 deletions.
6 changes: 4 additions & 2 deletions packages/monaco/src/browser/monaco-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export function loadMonaco(vsRequire: any): Promise<void> {
'vs/platform/contextkey/common/contextkey',
'vs/platform/contextkey/browser/contextKeyService',
'vs/editor/common/model/wordHelper',
'vs/base/common/errors'
'vs/base/common/errors',
'vs/base/common/path'
], (commands: any, actions: any,
keybindingsRegistry: any, keybindingResolver: any, resolvedKeybinding: any, keybindingLabels: any,
keyCodes: any, mime: any, editorExtensions: any, simpleServices: any,
Expand All @@ -89,7 +90,7 @@ export function loadMonaco(vsRequire: any): Promise<void> {
markerService: any,
contextKey: any, contextKeyService: any,
wordHelper: any,
error: any) => {
error: any, path: any) => {
const global: any = self;
global.monaco.commands = commands;
global.monaco.actions = actions;
Expand All @@ -111,6 +112,7 @@ export function loadMonaco(vsRequire: any): Promise<void> {
global.monaco.mime = mime;
global.monaco.wordHelper = wordHelper;
global.monaco.error = error;
global.monaco.path = path;
resolve();
});
});
Expand Down
5 changes: 5 additions & 0 deletions packages/monaco/src/typings/monaco/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,11 @@ declare module monaco.error {
export function onUnexpectedError(e: any): undefined;
}

declare module monaco.path {
// https://github.com/microsoft/vscode/blob/320fbada86c113835aef4fb9d7c4bc5b74678166/src/vs/base/common/path.ts#L1494
export function normalize(path: string): string;
}

declare module monaco.wordHelper {
// https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/editor/common/model/wordHelper.ts#L30
export const DEFAULT_WORD_REGEXP: RegExp;
Expand Down
66 changes: 43 additions & 23 deletions packages/plugin-ext/src/main/browser/languages-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {
MarkerSeverity, DocumentLink, WorkspaceSymbolParams, CodeAction, CompletionDto
} from '../../common/plugin-api-rpc-model';
import { RPCProtocol } from '../../common/rpc-protocol';
import { fromLanguageSelector } from '../../plugin/type-converters';
import { DocumentFilter, MonacoModelIdentifier, testGlob } from 'monaco-languageclient/lib';
import { MonacoLanguages } from '@theia/monaco/lib/browser/monaco-languages';
import CoreURI from '@theia/core/lib/common/uri';
Expand All @@ -51,13 +50,14 @@ import * as vst from 'vscode-languageserver-types';
import * as theia from '@theia/plugin';
import { UriComponents } from '../../common/uri-components';
import { CancellationToken } from '@theia/core/lib/common';
import { LanguageSelector } from '@theia/languages/lib/common/language-selector';
import { LanguageSelector, RelativePattern } from '@theia/languages/lib/common/language-selector';
import { CallHierarchyService, CallHierarchyServiceProvider, Caller, Definition } from '@theia/callhierarchy/lib/browser';
import { toDefinition, toUriComponents, fromDefinition, fromPosition, toCaller } from './callhierarchy/callhierarchy-type-converters';
import { Position, DocumentUri } from 'vscode-languageserver-types';
import { ObjectIdentifier } from '../../common/object-identifier';
import { WorkspaceSymbolProvider } from '@theia/languages/lib/browser/language-client-services';
import { mixin } from '../../common/types';
import { relative } from '../../common/paths-util';

@injectable()
export class LanguagesMainImpl implements LanguagesMain, Disposable {
Expand Down Expand Up @@ -127,7 +127,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerCompletionSupport(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[], triggerCharacters: string[], supportsResolveDetails: boolean): void {
this.register(handle, monaco.modes.CompletionProviderRegistry.register(fromLanguageSelector(selector), {
this.register(handle, monaco.modes.CompletionProviderRegistry.register(this.toLanguageSelector(selector), {
triggerCharacters,
provideCompletionItems: (model, position, context, token) => this.provideCompletionItems(handle, model, position, context, token),
resolveCompletionItem: supportsResolveDetails
Expand Down Expand Up @@ -164,19 +164,19 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerDefinitionProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const definitionProvider = this.createDefinitionProvider(handle);
this.register(handle, monaco.languages.registerDefinitionProvider(languageSelector, definitionProvider));
}

$registerDeclarationProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const declarationProvider = this.createDeclarationProvider(handle);
this.register(handle, monaco.languages.registerDeclarationProvider(languageSelector, declarationProvider));
}

$registerReferenceProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const referenceProvider = this.createReferenceProvider(handle);
this.register(handle, monaco.languages.registerReferenceProvider(languageSelector, referenceProvider));
}
Expand Down Expand Up @@ -207,7 +207,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerSignatureHelpProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[], metadata: theia.SignatureHelpProviderMetadata): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const signatureHelpProvider = this.createSignatureHelpProvider(handle, metadata);
this.register(handle, monaco.languages.registerSignatureHelpProvider(languageSelector, signatureHelpProvider));
}
Expand All @@ -226,7 +226,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerImplementationProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const implementationProvider = this.createImplementationProvider(handle);
this.register(handle, monaco.languages.registerImplementationProvider(languageSelector, implementationProvider));
}
Expand Down Expand Up @@ -262,7 +262,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerTypeDefinitionProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const typeDefinitionProvider = this.createTypeDefinitionProvider(handle);
this.register(handle, monaco.languages.registerTypeDefinitionProvider(languageSelector, typeDefinitionProvider));
}
Expand Down Expand Up @@ -298,7 +298,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerHoverProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const hoverProvider = this.createHoverProvider(handle);
this.register(handle, monaco.languages.registerHoverProvider(languageSelector, hoverProvider));
}
Expand All @@ -315,7 +315,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerDocumentHighlightProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const documentHighlightProvider = this.createDocumentHighlightProvider(handle);
this.register(handle, monaco.languages.registerDocumentHighlightProvider(languageSelector, documentHighlightProvider));
}
Expand Down Expand Up @@ -370,7 +370,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerDocumentLinkProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const linkProvider = this.createLinkProvider(handle);
this.register(handle, monaco.languages.registerLinkProvider(languageSelector, linkProvider));
}
Expand Down Expand Up @@ -412,7 +412,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerCodeLensSupport(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[], eventHandle: number): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const lensProvider = this.createCodeLensProvider(handle);

if (typeof eventHandle === 'number') {
Expand Down Expand Up @@ -461,7 +461,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerOutlineSupport(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const symbolProvider = this.createDocumentSymbolProvider(handle);
this.register(handle, monaco.modes.DocumentSymbolProviderRegistry.register(languageSelector, symbolProvider));
}
Expand Down Expand Up @@ -563,7 +563,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerDocumentFormattingSupport(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const documentFormattingEditSupport = this.createDocumentFormattingSupport(handle);
this.register(handle, monaco.languages.registerDocumentFormattingEditProvider(languageSelector, documentFormattingEditSupport));
}
Expand All @@ -580,7 +580,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerRangeFormattingProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const rangeFormattingEditProvider = this.createRangeFormattingProvider(handle);
this.register(handle, monaco.languages.registerDocumentRangeFormattingEditProvider(languageSelector, rangeFormattingEditProvider));
}
Expand All @@ -597,7 +597,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerOnTypeFormattingProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[], autoFormatTriggerCharacters: string[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const onTypeFormattingProvider = this.createOnTypeFormattingProvider(handle, autoFormatTriggerCharacters);
this.register(handle, monaco.languages.registerOnTypeFormattingEditProvider(languageSelector, onTypeFormattingProvider));
}
Expand All @@ -618,7 +618,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerFoldingRangeProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const provider = this.createFoldingRangeProvider(handle);
this.register(handle, monaco.languages.registerFoldingRangeProvider(languageSelector, provider));
}
Expand All @@ -635,7 +635,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerSelectionRangeProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const provider = this.createSelectionRangeProvider(handle);
this.register(handle, monaco.languages.registerSelectionRangeProvider(languageSelector, provider));
}
Expand All @@ -652,7 +652,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerDocumentColorProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const colorProvider = this.createColorProvider(handle);
this.register(handle, monaco.languages.registerColorProvider(languageSelector, colorProvider));
}
Expand Down Expand Up @@ -698,7 +698,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerQuickFixProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[], providedCodeActionKinds?: string[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const quickFixProvider = {
provideCodeActions: (model: monaco.editor.ITextModel, range: monaco.Range,
context: monaco.languages.CodeActionContext, token: monaco.CancellationToken): monaco.languages.CodeActionList | Promise<monaco.languages.CodeActionList> => {
Expand Down Expand Up @@ -728,7 +728,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerRenameProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[], supportsResolveLocation: boolean): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const renameProvider = this.createRenameProvider(handle, supportsResolveLocation);
this.register(handle, monaco.languages.registerRenameProvider(languageSelector, renameProvider));
}
Expand All @@ -750,7 +750,7 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
}

$registerCallHierarchyProvider(handle: number, selector: SerializedDocumentFilter[]): void {
const languageSelector = fromLanguageSelector(selector);
const languageSelector = this.toLanguageSelector(selector);
const callHierarchyService = this.createCallHierarchyService(handle, languageSelector);
this.register(handle, this.callHierarchyServiceContributionRegistry.add(callHierarchyService));
}
Expand Down Expand Up @@ -804,6 +804,26 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
return this.proxy.$resolveRenameLocation(handle, model.uri, position, token);
}

protected toLanguageSelector(filters: SerializedDocumentFilter[]): monaco.modes.LanguageSelector & LanguageSelector {
return filters.map(filter => {
let pattern: string | (monaco.modes.IRelativePattern & RelativePattern) | undefined;
if (typeof filter.pattern === 'string') {
pattern = filter.pattern;
} else if (filter.pattern) {
pattern = {
base: monaco.path.normalize(filter.pattern.base),
pattern: filter.pattern.pattern,
pathToRelative: relative
};
}
return {
language: filter.language,
scheme: filter.scheme,
pattern
};
});
}

}

function reviveMarker(marker: MarkerData): vst.Diagnostic {
Expand Down
18 changes: 0 additions & 18 deletions packages/plugin-ext/src/plugin/type-converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,24 +316,6 @@ export function fromTextEdit(edit: theia.TextEdit): model.TextEdit {
};
}

export function fromLanguageSelector(selector: undefined): undefined;
export function fromLanguageSelector(selector: theia.DocumentSelector): LanguageSelector;
export function fromLanguageSelector(selector: undefined | theia.DocumentSelector): undefined | LanguageSelector {
if (!selector) {
return undefined;
} else if (Array.isArray(selector)) {
return <LanguageSelector>selector.map(fromLanguageSelector);
} else if (typeof selector === 'string') {
return selector;
} else {
return <LanguageFilter>{
language: selector.language,
scheme: selector.scheme,
pattern: fromGlobPattern(selector.pattern!)
};
}
}

export function convertDiagnosticToMarkerData(diagnostic: theia.Diagnostic): model.MarkerData {
return {
code: convertCode(diagnostic.code),
Expand Down

0 comments on commit 6021f3a

Please sign in to comment.