indexStub not being called and index is empty

I've been following http://www.jetbrains.org/intellij/sdk/docs/basics/indexing_and_psi_stubs/stub_indexes.html while looking at https://github.com/ignatov/intellij-erlang/commit/87ad1f4d8ddeba7f7d5f21b1a8e85cd24cd03628# for a real world example of building a stub index.   I have an index:

 
package org.elixir_lang.psi.stub.index;

import
com.intellij.psi.stubs.StringStubIndexExtension;
import
com.intellij.psi.stubs.StubIndexKey;
import
org.elixir_lang.psi.NamedElement;
import org.jetbrains.annotations.NotNull;

public class
AllName extends StringStubIndexExtension<NamedElement> {
    public static final StubIndexKey<String, NamedElement> KEY = StubIndexKey.createIndexKey("elixir.all.name");
    public static final int VERSION
= 0;

    @Override
    public int getVersion
() {
        return super.getVersion() + VERSION;
    
}

    @NotNull
    @Override
    public
StubIndexKey<String, NamedElement> getKey() {
        return KEY;
    
}
}


That I register in plugin.xml

 
<idea-plugin version="2">
 
 
package org.elixir_lang.psi.stub;

import
com.intellij.psi.stubs.IStubElementType;
import
com.intellij.psi.stubs.NamedStubBase;
import
com.intellij.psi.stubs.StubElement;
import
com.intellij.util.io.StringRef;
import
org.elixir_lang.psi.ElixirAlias;
import org.jetbrains.annotations.Nullable;

public class
Alias extends NamedStubBase<ElixirAlias> {
    public Alias(StubElement parent, IStubElementType elementType, @Nullable String name) {
        super(parent, elementType, name);
    
}

    public Alias(StubElement parent, IStubElementType elementType, StringRef nameRef) {
        super(parent, elementType, nameRef);
    
}
}


Stub type:

 
package org.elixir_lang.psi.stub.type;

import
com.intellij.psi.stubs.IndexSink;
import
com.intellij.psi.stubs.StubElement;
import
com.intellij.psi.stubs.StubInputStream;
import
com.intellij.psi.stubs.StubOutputStream;
import
org.elixir_lang.psi.ElixirAlias;
import
org.elixir_lang.psi.impl.ElixirAliasImpl;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

import
java.io.IOException;

public class
Alias extends Named<org.elixir_lang.psi.stub.Alias, ElixirAlias> {
    /*
     * Constructors
     */

    public
Alias(@NonNls @NotNull String debugName) {
        super(debugName);
    
}

    /*
     * Instance Methods
     */

    @NotNull
    @Override
    public
org.elixir_lang.psi.stub.Alias deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
        return new org.elixir_lang.psi.stub.Alias(parentStub, this, dataStream.readName());
    
}

    @Override
    public
ElixirAlias createPsi(@NotNull org.elixir_lang.psi.stub.Alias stub) {
        return new ElixirAliasImpl(stub, this);
    
}

    @Override
    public
org.elixir_lang.psi.stub.Alias createStub(ElixirAlias psi, StubElement parentStub) {
        return new org.elixir_lang.psi.stub.Alias(parentStub, this, psi.getName());
    
}

    @Override
    public void indexStub
(@NotNull final org.elixir_lang.psi.stub.Alias stub, @NotNull final IndexSink sink) {
        int a = 1; // THIS IS NOT RUN
    
}

    @Override
    public void serialize
(final @NotNull org.elixir_lang.psi.stub.Alias stub, @NotNull StubOutputStream dataStream) throws IOException {
        dataStream.writeName(stub.getName());
    
}
}


Just for context, Aliases are the Camel.Case.Dotted.Names in Elixir, so I want them indexed as they are used for Module names, whic would map to class names in Java.  If there's a better way to index "class names" that I missed let me know.

Why isn't indexStub being called and the AllName index being populated?

6 comments
Comment actions Permalink

Check your StubBuilder is really producing stub node that you want to index.

0
Comment actions Permalink

createStub is being called when I place a breakpoint in its body.  (I assume by one of the built-in StubBuilder implementations.)  My understanding of http://www.jetbrains.org/intellij/sdk/docs/basics/indexing_and_psi_stubs/stub_indexes.html was that I didn't have to write my own StubBuilder, just implement the createStub method as I have.   Is that not correct?

0
Comment actions Permalink

Sorry, I just realized I did setup a StubBuilder, but as an anonymous subclass inside of the ElementType for my File.  I didn't remember it because I was copy and modifying from intellij-erlang, so I didn't actualy type StubBuilder:

package org.elixir_lang.psi.stub.type;

 

import com.intellij.psi.PsiFile;
import
com.intellij.psi.StubBuilder;
import
com.intellij.psi.stubs.DefaultStubBuilder;
import
com.intellij.psi.stubs.StubElement;
import
com.intellij.psi.tree.IStubFileElementType;
import
org.elixir_lang.ElixirLanguage;
import
org.elixir_lang.psi.ElixirFile;
import org.jetbrains.annotations.NotNull;

public class
File extends IStubFileElementType<org.elixir_lang.psi.stub.File> {
    public static final int VERSION = 1;
    public static final
IStubFileElementType INSTANCE = new File();

    public
File() {
        super("ELIXIR_FILE", ElixirLanguage.INSTANCE);
    
}

    @Override
    public
StubBuilder getBuilder() {
        return new DefaultStubBuilder() {
            @Override
            protected
StubElement createStubForFile(@NotNull PsiFile file) {
                if (file instanceof ElixirFile) {
                    return new org.elixir_lang.psi.stub.File((ElixirFile) file);
                
}
                return super.createStubForFile(file);
            
}
        };
    
}
}
0
Comment actions Permalink

So far I've only written the stubs for the File and the Alias, but an Alias in a `defmodule` call isn't a direct child of a File node.  Does this matter?  The docs said I could leave elements out of the stub, but do I need all the elements along a hierarcyh from the file to the element I want indexed to have stubs?

0
Comment actions Permalink

It looks like my stub.type.File was just incomplete because I missed copying some of the method overrides.  With this version of the class, I get a built index:

 
package org.elixir_lang.psi.stub.type;

import
com.intellij.psi.PsiFile;
import
com.intellij.psi.StubBuilder;
import
com.intellij.psi.stubs.DefaultStubBuilder;
import
com.intellij.psi.stubs.StubElement;
import
com.intellij.psi.stubs.StubInputStream;
import
com.intellij.psi.stubs.StubOutputStream;
import
com.intellij.psi.tree.IStubFileElementType;
import
org.elixir_lang.ElixirLanguage;
import
org.elixir_lang.psi.ElixirFile;
import org.jetbrains.annotations.NotNull;

import
java.io.IOException;

public class
File extends IStubFileElementType<org.elixir_lang.psi.stub.File> {
    public static final int VERSION = 1;
    public static final
IStubFileElementType INSTANCE = new File();

    public
File() {
        super("ELIXIR_FILE", ElixirLanguage.INSTANCE);
    
}

    @Override
    public
StubBuilder getBuilder() {
        return new DefaultStubBuilder() {
            @Override
            protected
StubElement createStubForFile(@NotNull PsiFile file) {
                if (file instanceof ElixirFile) {
                    return new org.elixir_lang.psi.stub.File((ElixirFile) file);
                
}
                return super.createStubForFile(file);
            
}
        };
    
}

    @Override
    public int getStubVersion
() {
        return VERSION;
    
}

    @Override
    public void serialize
(@NotNull org.elixir_lang.psi.stub.File stub, @NotNull StubOutputStream dataStream) throws IOException {
    }

    @NotNull
    @Override
    public
org.elixir_lang.psi.stub.File deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
        return new org.elixir_lang.psi.stub.File(null);
    
}

    @NotNull
    @Override
    public
String getExternalId() {
        return "elixir.FILE";
    
}
}
0
Comment actions Permalink

No, you don't. You can skip elements you don't care about.


0

Please sign in to leave a comment.