ligasgr / intellij-xquery

Plugin to support XQuery in Intellij Idea
Apache License 2.0
35 stars 23 forks source link

else not always picked up by autocomplete #157

Closed rhdunn closed 8 years ago

rhdunn commented 8 years ago

Given:

declare function foo($foo as element(bar)) {
    if ($foo) then
        ()
    <caret>
};

()

where <caret> is the current cursor position, typing el does not resolve else as a possible keyword in the autocomplete box.

NOTE: The input:

if ($foo) then
    ()
<caret>

on its own does pick up else as a possible keyword in autocomplete.

ligasgr commented 8 years ago

Hey I must be doing something wrong as I cannot reproduce your issue... Please note that I've checked it on both XQuery Standard 3.0 and Marklogic 8 flavours. Please see screenshots attached. First one is when I started typing el in the place. else-screen

Second one is when I pressed ctrl-space in the place of cursor and started navigating the list. else-pick

Can you please add more details on when the issue happens and how it looks like?

rhdunn commented 8 years ago

This is what I am seeing: else-autocomplete

In your Ctrl+Space screenshot, I am not seeing else or every in the list from my setup.

This is using the release version of the xquery plugin 3.0.0.

ligasgr commented 8 years ago

Can you please let me know of there's any exception notification related to this? Also can you please share your idea.log? It's in the Idea log directory (idea.log.path property in idea.properties).

rhdunn commented 8 years ago

The idea.log file does not have any exceptions relevant to this.

I have done some investigation into this issue...

In src/main/java/org/intellij/xquery/completion/keyword/KeywordCollector.java:

  1. suggestKeywordsBasedOnParserExpectedKeywords is being called with getPrecedingText containing:

    declare function foo($foo) {
       if (empty($foo)) then
           ()
       [EOS]

    where [EOS] is used to preserve whitespace in the last line.

  2. The convertItem method on the getCompletionStateForKeywords handler is being called with the else keyword as an IElementType (so is correctly returning the else string).
  3. completionStateInTemporaryFile.items contains [document, ordered, unordered, declare, function, replace, processing-instruction, following-sibling, following, schema-element, switch, intersect, comment, preceding-sibling, castable, parent, except, preceding, ancestor, namespace, descendant-or-self, descendant, schema-attribute, validate, instance, typeswitch, attribute, document-node, rename, ancestor-or-self, namespace-node, element].

Looking at https://android.googlesource.com/platform/tools/idea/+/snapshot-master/platform/lang-impl/src/com/intellij/lang/parser/GeneratedParserUtilBase.java, the function private static void addCompletionVariant(@NotNull PsiBuilder builder_, @NotNull CompletionState completionState, Object o) method looks like the place where items are being added. I am not currently sure what is preventing that item from being added.

ligasgr commented 8 years ago

Hi

Can you please try on the latest code from trunk if the issue is getting resolved (else is always picked up)?

ligasgr commented 8 years ago

I assume it fixed the issue. If not, please re-open.