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

[Bug] Duplicated function in intellisense after addExtraLib #3580

Open
1 of 2 tasks
Shaddix opened this issue Feb 21, 2023 · 5 comments
Open
1 of 2 tasks

[Bug] Duplicated function in intellisense after addExtraLib #3580

Shaddix opened this issue Feb 21, 2023 · 5 comments
Labels
bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities open for PR Chances are high we accept a PR for this issue (even if it got closed). typescript

Comments

@Shaddix
Copy link

Shaddix commented Feb 21, 2023

Reproducible in vscode.dev or in VS Code Desktop?

  • Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.35.0#XQAAAAI_AgAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw0ujCMH_KmaUY-oS3CKMkOSajRHzMOh275SgQndWdGyFPATHN_jQG5rOFPT-L8kRd7Az7STn-1YydGSUXwZb8WhGo0LTm9LMOTHHaW-VuaVSEvOtnVqiQcdHtSbJ-MXc4sDBPYRWn9llPd7wkQFMjP-1wIbhnirKgcQ6QYJQWrxfa5BkiuTVNdyljIo8gJsjLpnqDCMW2vX2xR9_7xYNQp_SXP3TiWFimDIX7MBNCCrUtv7Nd9PsGeM7tIg-NcKx52fdfiUJveVPjdykEcohN41wWUrSv8oYLJ8Af0x3ExQXC2m0G-b9UaPGF7dlYR039F7NJ9lOEbgZxN7ctjDPUEqzsRJxEzrYKPxox8liDi33QpT9c_SyopAHM4Fb3JbbAibxH5CF4N0IYWmqkV5veef-yegA-hf7_oC_zRsjSABnU_ySaVgA

Monaco Editor Playground Code

// The Monaco Editor can be easily created, given an
// empty container and an options literal.
// Two members of the literal are "value" and "language".
// The editor takes the full size of its container.

monaco.editor.create(document.getElementById("container"), {
	value: "function hello() {\n\talert('Hello world!');\ntrim()}",
	language: "typescript",
});
monaco.languages.typescript.typescriptDefaults.addExtraLib(
            'function trim(s: string):string;',
            'index.d.ts',
          );

Reproduction Steps

hover over trim function in Preview pane.
Tooltip will be shown: 'function trim(s: string): string (+1 overload)'
image
(+1 overload) is not expected (since I only defined a single trim function).

Similar thing happens if I type trim( to see autocompletion. It shows like there are 2 overloads of trim function, while actually there's only one.
image

Actual (Problematic) Behavior

editor behaves like addExtraLib is called twice and shows 2 identical overloads of a function defined in addExtraLib

Expected Behavior

I'd expect a single overload of trim function to exist in autocomplete.

Additional Context

No response

@Shaddix Shaddix changed the title [Bug] [Bug] Duplicated function in intellisense after addExtraLib Feb 21, 2023
@hediet hediet added bug Issue identified by VS Code Team member as probable bug typescript labels Feb 21, 2023
@hediet
Copy link
Member

hediet commented Feb 24, 2023

It would be awesome if you could investigate this bug!

Here is our guide how to debug the language support of the monaco editor:
https://github.com/microsoft/monaco-editor/blob/main/CONTRIBUTING.md#debugging--developing-language-support

@hediet hediet added help wanted Issues identified as good community contribution opportunities open for PR Chances are high we accept a PR for this issue (even if it got closed). labels Feb 24, 2023
@Jaxkr
Copy link

Jaxkr commented Feb 12, 2024

I also have this bug!

@Jaxkr
Copy link

Jaxkr commented Feb 12, 2024

It would be awesome if you could investigate this bug!

Here is our guide how to debug the language support of the monaco editor: https://github.com/microsoft/monaco-editor/blob/main/CONTRIBUTING.md#debugging--developing-language-support

Hey @hediet , trying to fix this bug and I'm running into issues with the instructions: #4383

@Jaxkr
Copy link

Jaxkr commented Mar 3, 2024

I found the source of this bug!

The function at getOrCreateModel at https://github.com/microsoft/monaco-editor/blob/main/src/language/typescript/languageFeatures.ts#L116 is being called when the editor tries to autocomplete the function that's in addExtraLib for the first time. It creates a new model that duplicates the content which leads to this false overload error:
image

This can be fixed by returning null always on getOrCreateModel (seems to have no negative consequences, everything still works).

Alternatively, you can create a model to store the extralib content which also fixes this bug:

const filename = "importedlibs.d.ts";
const a = monaco.editor.createModel(
  `declare module '@test/math' {
	export function myFunFunction(a: number, b: number): number
	}`,
  "typescript",
  monaco.Uri.file(filename)
);

const disposable = monaco.languages.typescript.typescriptDefaults.addExtraLib(
  a.getValue(),
  monaco.Uri.file(filename).toString()
);

Given that using addExtraLib will always result in the internal creation of a model, I think the code snippet above may be the correct (undocumented?) way to use this functionality.

@jcarrus
Copy link

jcarrus commented Dec 1, 2024

@Shaddix , I think #4544 fixes this issue, but it seems like we need some more community approvals to continue. Could you look and test that PR?

Also, @Jaxkr if you wanted to look, I think the change in #4544 works in a similar way to what you are suggesting. I think that your proposed fix of never creating a model here doesn't fix the case where a model for the extra lib is legitimately opened, such as when a user "peeks" the definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities open for PR Chances are high we accept a PR for this issue (even if it got closed). typescript
Projects
None yet
Development

No branches or pull requests

4 participants