How could I get a valid LookupElement set for the path auto completion?

Hi, 

I'm developing a plugin for the NEJ, which is a JavaScript framework. It's package resolve is similar to the define.js. The grammar shows below.

NEJ.define([
    'base/element',
    'pro/extend/util',
    '/path/to/file.js',
    '{platform}patch.js',
    'text!/path/to/file.css',
    'text!/path/to/file.html'
],function(e,u,t,h,css,html,p,o,f,r){

    // TODO something

    // 返回结果可注入给其他文件
    return p;
});


I have implement a class extending PsiReferenceBase<PsiElement>, and make the method resolve work well.
Now I wanna to implement getVariants which offering us a auto-completion. But I have encountered some problem. For example, when I type "./"and trigger basic-completion, I resolve the path "./", and get all children of the directory. And then, use the code:

 

final VirtualFile fileByPath = LocalFileSystem.getInstance().findFileByPath(String.valueOf(path.normalize()));

final PsiManager instance = PsiManager.getInstance(myElement.getProject());

for (VirtualFile file : fileByPath.getChildren()) {
// .withTypeText(file.getName())

if (file.isDirectory()) {
final PsiDirectory file1 = instance.findDirectory(file);
completionResultSet.add(
LookupElementBuilder
.create(file1).withTypeText(file1.getName())

);
}else{
final PsiFile file1 = instance.findFile(file);
completionResultSet.add(
LookupElementBuilder
.create(file1).withTypeText(file1.getName())

);
}
}


to return a completionResultSet. And this is my debug result:


You can see, it do have correct completion suggestions, but the IDE says there is no suggestions. I have found thatsomeone said getVariants should give all those resolvable but not matching all string. I can't understand it. Could someone tell me how to fixed it?


 
0
正式评论

Completion infrastructure uses the part before the caret of your reference's text to filter out completion variants. So if their lookup strings don't match that prefix, they won't be shown. If you want to match only the part after the slash, you should use several references, one for each part of the path. For that, we have FileReferenceSet/FileReference API that's a bit clumsy but you might consider using it.

Never mind. I have fixed this problem. Just remember the lookupstring of lookupitem should have the same prefix which is the content of myInRangeElement. Am I wrong?

0

Thanks Peter. I'll look into the api you offered.

0

请先登录再写评论。