halirutan / Wolfram-Language-IntelliJ-Plugin-Archive

Wolfram Language and Mathematica plugin for IntelliJ IDEA.
https://wlplugin.halirutan.de/
Other
193 stars 26 forks source link

Symbols incorrectly offered from Global context during auto-completion #151

Closed szhorvat closed 4 years ago

szhorvat commented 4 years ago

When I explicitly trigger auto-completion, I get symbols in the Global context that should not be there.

Example:

Suppose we want Internal`NonNegativeMachineIntegerQ. I often rely on auto-completion, because I can't remember which of these symbols is in which context (Developer, Internal, etc.)

Type NagetiveMa and press the shortcut for triggering completion. I see this:

image

This is in a scratch buffer. Can you reproduce it?

halirutan commented 4 years ago

One important question is: How often did you press Cmd+Space before the global symbols appear? I have different "layers" of autocompletion and the more often you press it manually, the more things will appear in some contexts.

One suspicion I have is that you used NegativeMachineIntegerQ inside your file(s) and at some point, the autocompletion will suggest it because it will give you a list of all symbols you used (no matter if they make sense). And since I'm not determining contexts inside files, it gets the Global prefix.

This is only a guess on my side and I have to check when I'm home.

szhorvat commented 4 years ago

Firs I type NonNegativeMa, at which point there are no completions offered without asking for any explicitly. Then I use Code -> Completion -> Basic precisely once (I have different shortcuts assigned and I wanted to make sure that there is no mistake made, so I used the menu this time). Then I get this:

image

This is now in a project where I did not use NonNegativeMachineIntegerQ at all (verified with grep).

If I complete it, it is coloured in blue:

image

halirutan commented 4 years ago

Thanks! Let me have a look at this.

halirutan commented 4 years ago

@szhorvat The good news is that your specific issue was an oversight of me. I did not exclude the Global` context when scraping the kernel for all available symbols. The symbols are put in JSON files and used for autocompletion.

The scary part is that something polluted the global context when I did nothing more than accessing available symbols. Sure is that I never used NonNegativeMachineIntegerQ or any other of the about 100 symbols that made it into the global context.

I will include the fix in the next version, but I'll keep this issue open until I had a closer look at the created symbol and context lists.

halirutan commented 4 years ago

Btw, the source code that is used for gathering all information is public. Something like this

PacletDirectoryAdd["XXX/Wolfram-IntelliJ-Tools/IntelliJTools/IntelliJTools"];
<< IntelliJTools`
SaveCompleteMathematicaInformation["existing/directory"]

will create 5 JSON files under the specified directory with all information.