-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[monaco] As an extension developer I want to customize which modules are loaded from monaco #8220
Comments
@kittaakos But I faced with the problem: Monaco loader did not bring comparers despite I added the corresponding items to Monaco loader here |
What did you do, @RomanNikitenko? It should work, I never had issues loading an additional monaco module before? Do you have a branch you can share? I want to look into it. We could use |
Could it be the following issue? #7522 |
@kittaakos Please let me know if I'm doing something wrong... |
I see what you're trying to do; your use-case is a bit different. It won't work for several reasons.
But I think we could achieve it with a small modification: diff --git a/packages/monaco/src/browser/monaco-loader.ts b/packages/monaco/src/browser/monaco-loader.ts
index d3aeaf041..177dc535d 100644
--- a/packages/monaco/src/browser/monaco-loader.ts
+++ b/packages/monaco/src/browser/monaco-loader.ts
@@ -76,6 +76,7 @@ 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/comparers',
'vs/base/common/errors'
], (commands: any, actions: any,
keybindingsRegistry: any, keybindingResolver: any, resolvedKeybinding: any, keybindingLabels: any,
@@ -89,6 +90,7 @@ export function loadMonaco(vsRequire: any): Promise<void> {
markerService: any,
contextKey: any, contextKeyService: any,
wordHelper: any,
+ comparers: any,
error: any) => {
const global: any = self;
global.monaco.commands = commands;
@@ -110,6 +112,7 @@ export function loadMonaco(vsRequire: any): Promise<void> {
global.monaco.contextKeyService = contextKeyService;
global.monaco.mime = mime;
global.monaco.wordHelper = wordHelper;
+ global.monaco.comparers = comparers;
global.monaco.error = error;
resolve();
});
diff --git a/packages/monaco/src/browser/monaco-quick-open-service.ts b/packages/monaco/src/browser/monaco-quick-open-service.ts
index 7a150ec82..0eb775e0d 100644
--- a/packages/monaco/src/browser/monaco-quick-open-service.ts
+++ b/packages/monaco/src/browser/monaco-quick-open-service.ts
@@ -355,11 +355,31 @@ export class MonacoQuickOpenControllerOptsImpl implements MonacoQuickOpenControl
}
}
if (this.options.fuzzySort) {
- entries.sort((a, b) => monaco.quickOpen.compareEntries(a, b, lookFor));
+ entries.sort((a, b) => {
+ const normalizedQuery = lookFor.toLowerCase();
+ return this.compareEntries(a, b, normalizedQuery);
+ });
}
return new monaco.quickOpen.QuickOpenModel(entries, actionProvider ? new MonacoQuickOpenActionProvider(actionProvider) : undefined);
}
+ protected compareEntries(elementA: monaco.quickOpen.QuickOpenEntry, elementB: monaco.quickOpen.QuickOpenEntry, lookFor: string): number {
+ const labelHighlightsA = elementA.getHighlights()[0] || [];
+ const labelHighlightsB = elementB.getHighlights()[0] || [];
+ if (labelHighlightsA.length && !labelHighlightsB.length) {
+ return -1;
+ }
+ if (!labelHighlightsA.length && labelHighlightsB.length) {
+ return 1;
+ }
+ if (labelHighlightsA.length === 0 && labelHighlightsB.length === 0) {
+ return 0;
+ }
+ const saneLabelA = (elementA.getLabel() || '').replace(/\r?\n/g, ' ');
+ const saneLabelB = (elementB.getLabel() || '').replace(/\r?\n/g, ' ');
+ return monaco.comparers.compareAnything(saneLabelA, saneLabelB, lookFor);
+ }
+
getModel(lookFor: string): monaco.quickOpen.QuickOpenModel {
throw new Error('getModel not supported!');
}
diff --git a/packages/monaco/src/typings/monaco/index.d.ts b/packages/monaco/src/typings/monaco/index.d.ts
index a9e0b9451..762a57f5d 100644
--- a/packages/monaco/src/typings/monaco/index.d.ts
+++ b/packages/monaco/src/typings/monaco/index.d.ts
@@ -24,6 +24,11 @@ declare module monaco.instantiation {
}
}
+declare module monaco.comparers {
+ // https://github.com/theia-ide/vscode/blob/standalone/0.19.x/src/vs/base/common/comparers.ts#L125
+ export function compareAnything(one: string, other: string, lookFor: string): number;
+}
+
declare module monaco.editor {
export interface ICodeEditor { I have not tried it though. |
This one is correct, but it was removed. So I tried to load
|
@kittaakos There are only some part of my changes - I had a few minutes to do some draft to show how I tried to load the |
This is getting a bit off-topic from the original issue: let's figure out why did the VS code guys remove it and what do they use now. Update:
I still think this is the current VS Code way. 👆 |
@kittaakos
Agree, but I tried to avoid off-topic :-)
I tried your patch and got the same error as described #8220 (comment) So, the problem with loading comparers is still actual for me. Anyway @kittaakos thank you very much for your time you spent within my problem! |
fyi I don't think we want to expose loader, since there is a likelihood that we switch to other way to consume Monaco for: #7261 |
With the way we are now consuming monaco (direct imports via ESM), I don't think this is relevant anymore. |
On the top of the modules we load, I want to load
vs/base/common/comparers
and make it available under themonaco
namespace but as I see, I cannot use injection for themonaco-loader
.Feature Description:
The text was updated successfully, but these errors were encountered: