monaco-editor: web ide app worksapce/symbol Reuse document/symbol s…#47544
Merged
alexdima merged 3 commits intoApr 17, 2018
Conversation
Author
|
now, I can add a command my code:
import { QuickOutlineAction, SymbolEntry } from 'monaco-editor/esm/vs/editor/standalone/browser/quickOpen/quickOutline';
import { Mode } from 'monaco-editor/esm/vs/base/parts/quickopen/common/quickOpen';
export class WorkspaceQuickOutlineAction extends QuickOutlineAction {
constructor() {
super();
}
// overwrite
symbolEntry(...args) {
return new WorkspaceSymbolEntry(...args);
}
}
export class WorkspaceSymbolEntry extends SymbolEntry {
constructor(...args) {
super(...args)
}
// overwrite
run(mode, context) {
if (mode !== Mode.OPEN) return;
// to do
// workspace symbol
}
}lsp.js import { QuickOpenEditorWidget } from 'monaco-editor/esm/vs/editor/standalone/browser/quickOpen/quickOpenEditorWidget';
import { QuickOpenController } from 'monaco-editor/esm/vs/editor/standalone/browser/quickOpen/editorQuickOpen';
import { QuickOpenModel } from 'monaco-editor/esm/vs/base/parts/quickopen/browser/quickOpenModel';
import { WorkspaceQuickOutlineAction } from './workspace'
...
function request(editor, value) {
return this.getConnection(editor.model)
.sendRequest('workspace/symbol',
convert.MonacoToLsp.workspaceSymbol(value))
.then(symbol => convert.LspToMonaco.documentSymbol(symbol, editor.model.uri));
}
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_P, () => {
const { themeService, lastKnownEditorSelection } = QuickOpenController.get(editor);
this.widget = new QuickOpenEditorWidget(editor,
() => {},
() => {},
(value) => {
clearTimeout(this._timer);
this._timer = setTimeout(() => {
let promise = Promise.resolve([]);
if (value) promise = request(this.editor, value);
const workspaceQuickOutlineAction = new WorkspaceQuickOutlineAction();
promise.then(result => this.widget.setInput(
new QuickOpenModel(result),
getAutoFocus(value)
));
}, this.delay);
},
{
inputAriaLabel: 'workspace symbol'
},
themeService
);
this.widget.show('');
});then, I can reuse the // overwrite
run(mode, context) {
if (mode !== Mode.OPEN) return;
// to do
// workspace symbol
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

monaco-editor don't support
workspace/symbolNow, we are developing an web ide base on monaco-editor,

and we want to realize the
workspace/symbolfeature which can make multi files switch(cmd + p), just like:However, monaco-editor only support
document/symbol(cmd + shift + O).We want to reuse the
document/symbolui Widget to realizeworkspace/symbolfeature, but we meet an problew:SymbolEntrywas not export inquickOutline.ts, that I cannot change the action after select an item.if we export SymbolEntry, I can overwrite theSymbolEntry.prototype.runmethod in my code, like:```jsimport { QuickOutlineAction, SymbolEntry } from 'monaco-editor/esm/vs/editor/standalone/browser/quickOpen/quickOutline';editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_P, () => {SymbolEntry.prototype.customType = 'workspace';SymbolEntry.prototype.webideRun = SymbolEntry.prototype.run;SymbolEntry.prototype.run = function(...args) {if (this.customType !== 'workspace') {return this.webideRun(...args);}this.customType = '';// do something for workspace/symbol}(new QuickOutlineAction()).run('', eiditor);})