Skip to content

monaco-editor: Find model by resource in SimpleEditorModelResolverService - #85129

Merged
Alexandru Dima (alexdima) merged 1 commit into
microsoft:masterfrom
spahnke:reference-models
Nov 19, 2019
Merged

monaco-editor: Find model by resource in SimpleEditorModelResolverService#85129
Alexandru Dima (alexdima) merged 1 commit into
microsoft:masterfrom
spahnke:reference-models

Conversation

@spahnke

Copy link
Copy Markdown
Contributor

This PR fixes microsoft/monaco-editor#935

Currently, if you run the following code in the Monaco Playground and use "Peek Definition", or "Peek References" on the method next() in line 3, you get the error "Model not found" on the browser console. This is because the SimpleEditorModelResolverService only takes into account the currently attached model. This PR instead searches through all models.

const lib = `declare class Facts {
	/**
	 * Returns the next fact
	 *
	 * [Online documentation](http://www.google.de)
	 */
	static next(): string;
}`;

const uri = monaco.Uri.file("filename/facts.d.ts");
monaco.languages.typescript.javascriptDefaults.addExtraLib(lib, uri.toString());
monaco.editor.createModel(lib, "typescript", uri);

monaco.editor.create(document.getElementById("container"), {
    value: `class Chuck {
    greet() {
        return Facts.next();
    }
}`,
    language: "javascript"
});

Thanks!

@alexdima

Copy link
Copy Markdown
Member

👍 Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Peek reference and preview definition don't work across models

2 participants