@@ -18,65 +18,65 @@ import org.klesun.deep_js_completion.entry.PathStrGoToDecl
18
18
import org .klesun .deep_js_completion .resolvers .VarRes
19
19
20
20
object JsdocPvdr {
21
- private def getJsFiles (baseFile : PsiFile ): GenTraversableOnce [String ] = {
22
- FilenameIndex .getAllFilesByExt(baseFile.getProject, " js" ).asScala
23
- .filter(vf => ! Option (vf.getCanonicalPath).exists(path => path.contains(" /node_modules/" )))
24
- .map(f => f.getName)
25
- }
21
+ private def getJsFiles (baseFile : PsiFile ): GenTraversableOnce [String ] = {
22
+ FilenameIndex .getAllFilesByExt(baseFile.getProject, " js" ).asScala
23
+ .filter(vf => ! Option (vf.getCanonicalPath).exists(path => path.contains(" /node_modules/" )))
24
+ .map(f => f.getName)
25
+ }
26
26
27
- /** @param code = "at('SomeFile.js').someVarPart"
28
- * @return (String, String) - ("at('SomeFile.js').", "SomeFile.js", "someVarPart") */
29
- def matchAtModuleVarTaker (code : String ): Option [(String , String , String )] = {
30
- """ (at\('([^']+)'\)\.)([a-zA-Z_$][a-zA-Z_$0-9]*|)$""" .r.findFirstMatchIn(code)
31
- .map(found => (found.group(1 ), found.group(2 ), found.group(3 )))
32
- }
27
+ /** @param code = "at('SomeFile.js').someVarPart"
28
+ * @return (String, String) - ("at('SomeFile.js').", "SomeFile.js", "someVarPart") */
29
+ def matchAtModuleVarTaker (code : String ): Option [(String , String , String )] = {
30
+ """ (at\('([^']+)'\)\.)([a-zA-Z_$][a-zA-Z_$0-9]*|)$""" .r.findFirstMatchIn(code)
31
+ .map(found => (found.group(1 ), found.group(2 ), found.group(3 )))
32
+ }
33
33
34
- /** @param code = "require('NamePart" ?? "at('"
35
- * @return (String, String) - ("require('", "NamePart") */
36
- def matchFileNameTaker (code : String ): Option [(String , String )] = {
37
- """ ((?:require|at)\(['"])([a-zA-Z][a-zA-Z0-9_\$]*|)$""" .r.findFirstMatchIn(code)
38
- .map(found => (found.group(1 ), found.group(2 )))
39
- }
34
+ /** @param code = "require('NamePart" ?? "at('"
35
+ * @return (String, String) - ("require('", "NamePart") */
36
+ def matchFileNameTaker (code : String ): Option [(String , String )] = {
37
+ """ ((?:require|at)\(['"])([a-zA-Z][a-zA-Z0-9_\$]*|)$""" .r.findFirstMatchIn(code)
38
+ .map(found => (found.group(1 ), found.group(2 )))
39
+ }
40
40
}
41
41
42
42
class JsdocPvdr extends CompletionProvider [CompletionParameters ] {
43
- override def addCompletions (
44
- parameters : CompletionParameters ,
45
- context : ProcessingContext ,
46
- result : CompletionResultSet
47
- ) = {
48
- val prefix = parameters.getEditor.getDocument
49
- .getText(new TextRange (Math .max(parameters.getOffset - 100 , 0 ), parameters.getOffset))
50
- val postfix = parameters.getEditor.getDocument
51
- .getText(new TextRange (parameters.getOffset, Math .min(parameters.getOffset + 100 , parameters.getEditor.getDocument.getTextLength)))
52
- val ending = if (! postfix.startsWith(" '" ) && ! postfix.startsWith(" \" " )) " ')" else " "
53
- val lookups = nit(parameters.getOriginalFile).flatMap(f => cnc(
54
- matchFileNameTaker(prefix)
55
- .itr().flatMap(tuple => {
56
- // WebStorm splits leaf PSI-s by space
57
- val (leafStart, namePrefix) = tuple
58
- // excludes options not prefixed by the "require('"
59
- getJsFiles(f).itr().map(fname =>
60
- LookupElementBuilder .create(leafStart + fname + ending)
61
- .bold().withIcon(getIcon)
62
- )
63
- })
64
- ,
65
- matchAtModuleVarTaker(prefix)
66
- .itr().flatMap(tuple => {
67
- val (leafStart, fileName, varNamePrefix) = tuple
68
- PathStrGoToDecl .getReferencedFileAnyDir(fileName, f).itr()
69
- .flatMap(f => VarRes .findAllVarsAt(f))
70
- .map(v => v.getName)
71
- .flatMap(n =>
72
- getJsFiles(f).itr().map(fname =>
73
- LookupElementBuilder .create(leafStart + n)
74
- .bold().withIcon(getIcon)
75
- ))
76
- })
77
- ))
78
- lookups.foreach(l => {
79
- result.addElement(l)
80
- })
81
- }
43
+ override def addCompletions (
44
+ parameters : CompletionParameters ,
45
+ context : ProcessingContext ,
46
+ result : CompletionResultSet
47
+ ) = {
48
+ val prefix = parameters.getEditor.getDocument
49
+ .getText(new TextRange (Math .max(parameters.getOffset - 100 , 0 ), parameters.getOffset))
50
+ val postfix = parameters.getEditor.getDocument
51
+ .getText(new TextRange (parameters.getOffset, Math .min(parameters.getOffset + 100 , parameters.getEditor.getDocument.getTextLength)))
52
+ val ending = if (! postfix.startsWith(" '" ) && ! postfix.startsWith(" \" " )) " ')" else " "
53
+ val lookups = nit(parameters.getOriginalFile).flatMap(f => cnc(
54
+ matchFileNameTaker(prefix)
55
+ .itr().flatMap(tuple => {
56
+ // WebStorm splits leaf PSI-s by space
57
+ val (leafStart, namePrefix) = tuple
58
+ // excludes options not prefixed by the "require('"
59
+ getJsFiles(f).itr().map(fname =>
60
+ LookupElementBuilder .create(leafStart + fname + ending)
61
+ .bold().withIcon(getIcon)
62
+ )
63
+ })
64
+ ,
65
+ matchAtModuleVarTaker(prefix)
66
+ .itr().flatMap(tuple => {
67
+ val (leafStart, fileName, varNamePrefix) = tuple
68
+ PathStrGoToDecl .getReferencedFileAnyDir(fileName, f).itr()
69
+ .flatMap(f => VarRes .findAllVarsAt(f))
70
+ .map(v => v.getName)
71
+ .flatMap(n =>
72
+ getJsFiles(f).itr().map(fname =>
73
+ LookupElementBuilder .create(leafStart + n)
74
+ .bold().withIcon(getIcon)
75
+ ))
76
+ })
77
+ ))
78
+ lookups.foreach(l => {
79
+ result.addElement(l)
80
+ })
81
+ }
82
82
}
0 commit comments