How to registerCompletionItemProvider (and avoid duplicates)?

See original GitHub issue

Right now, I’m calling monaco.languages.registerCompletionItemProvider in the editorDidMount method. How would I prevent adding multiple completion providers if this component continuously gets mounted and unmounted? It doesn’t appear that monaco provides a unregister method and editor.dispose doesn’t remove additions made to monaco.languages

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12

github_iconTop GitHub Comments

16reactions
nickavcommented, Jan 22, 2018

nevermind, answered my own question. registerCompletionItemProvider returns an IDisposable with the dispose method which I can call on unmount

2reactions
JeremyRippertcommented, Aug 5, 2019

Hello @nickav , I ran into the same issue about registerCompletionItemProvider creating duplicates of my suggestions. However, I tried saving the IDisposable into a variable and using dispose() on unmount, without success.

Here is my code :

const [completionDisposable, setCompletionDisposable] = useState({});

  useEffect(
    () => () => {
      completionDisposable.dispose();
    },
    [],
  );

  const editorWillMount = (monaco: any) => {
    setMonacoObject(monaco);
    setCompletionDisposable(
      monaco.languages.registerCompletionItemProvider('vb', {
        provideCompletionItems() {
          return {
            suggestions: createAutoComplete(parameterList),
          };
        },
      }),
    );
  };

I get an error TypeError: completionDisposable.dispose is not a function anytime I leave the page.

Do you remember how you managed to dispose of the completionItemProvider ? Thanks in advance

Read more comments on GitHub >

github_iconTop Results From Across the Web

Duplicate Completion Item Provider - monaco editor
registerCompletionItemProvider is defined. If it is, I do not define it again, eliminating duplicate completions.
Read more >
Frontend: Add predefined variables to the linter schema - GitLab
I guess the only option we have now is to duplicate the list of predefined variables in frontend as we do in the...
Read more >
Use monaco-editor and registerCompletionItemProvider to ...
Use monaco-editor and registerCompletionItemProvider to register multiple times, which eventually leads to duplicate content of the displayed ...
Read more >
VS Code API | Visual Studio Code Extension API
registerCompletionItemProvider (selector: DocumentSelector, provider: ... that cause or related to a diagnostics, e.g. when duplicating a symbol in a scope.
Read more >
Show results from both word based suggestions and own ...
That is to avoid duplicates and spam. The doc comment of registerCompletionItemProvider() is still the same, so I don't think anything has ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found