Skip to content
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

RegisterCompletionItemProvider problem #138

Open
elgransan opened this issue Aug 16, 2024 · 1 comment
Open

RegisterCompletionItemProvider problem #138

elgransan opened this issue Aug 16, 2024 · 1 comment

Comments

@elgransan
Copy link

Hi, thanks for the port It's awesome.
I want to get the code selection from the provideCompletionItems delegate, like the javascript example on the Monaco playground:

monaco.languages.registerCompletionItemProvider("json", {
	provideCompletionItems: function (model, position) {
		var word = model.getWordUntilPosition(position);   <-- this
		var range = {
			startLineNumber: position.lineNumber,
			endLineNumber: position.lineNumber,
			startColumn: word.startColumn,
			endColumn: word.endColumn,
		};
		return {
			suggestions: createDependencyProposals(range),
		};
	},
});

But the wrapper sends a "modelUri" not the model itself, how can I convert this string to the real object? I tried using
BlazorMonaco.Editor.Global.GetModel(JsRuntime, modelUri); or also _editor.GetSelection() but there are not allowed async operations.

Thanks!

@brettwinters
Copy link

I have no idea also, but it seems you have to do something like this:

 await Global.RegisterCompletionItemProvider(JsRuntime, "sql", (model, position, context) =>
        {
            ArgumentNullException.ThrowIfNull(_editor);
            
            var text = _editor.GetModel().Result;
            var pos = _editor.GetPosition().Result;
            var word = text.GetWordUntilPosition(pos).Result.Word;

            if (word is not null &&
                word.Trim().EndsWith("FROM", StringComparison.InvariantCultureIgnoreCase))
            {
                   // return your list 
            }
}

In blazor this doesn't work because you can't call .Result on async methods so I'm trying to figure that out now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants