microsoft / microsoft/monaco-editor

go to definition - different model: loading via http

Open
#291 20 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request typescript typescript-multifile
Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

i'm adding a go to definition feature using a langserver.

monaco notices it's a new model 👍, and then tries to load it.
the ranges of the place that contains definition is correct.

does monaco support in-place replacement of the model?
what i'm seeing is that it just offers to download the whole
file containing the resulting definition, i.e., this line
window.open(data.resource.toString());.


https://github.com/Microsoft/vscode/blob/0d6a9f8389cd044851ac994e527969bd53d2d387/src/vs/editor/browser/standalone/simpleServices.ts#L134

in my monaco build:

private doOpenEditor(editor:editorCommon.ICommonCodeEditor, data:IResourceInput): IEditor {
	var model = this.findModel(editor, data);
	if (!model) {
		if (data.resource) {
			if (this.openEditorDelegate) {
				this.openEditorDelegate(data.resource.toString());
				return null;
			} else {
				var schema = data.resource.scheme;
				if (schema === Schemas.http || schema === Schemas.https) {
					// This is a fully qualified http or https URL
					window.open(data.resource.toString());
					return this.editor;
				}
			}
		}
		return null;
	}


	var selection = <editorCommon.IRange>data.options.selection;
	if (selection) {
		if (typeof selection.endLineNumber === 'number' && typeof selection.endColumn === 'number') {
			editor.setSelection(selection);
			editor.revealRangeInCenter(selection);
		} else {
			var pos = {
				lineNumber: selection.startLineNumber,
				column: selection.startColumn
			};
			editor.setPosition(pos);
			editor.revealPositionInCenter(pos);
		}
	}

	return this.editor;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with doOpenEditor in src/vs/editor/browser/standalone/simpleServices.ts, especially the handling of http and https resources when no model is found. Trace how go-to-definition supplies the resource and selection range. Done means a definition in a different HTTP-loaded model can open in place at the supplied range instead of triggering a download.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
devtools, frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.