Skip to content

Commit 6c63c24

Browse files
committed
Switch to tabs everywhere instead of 2 spaces
I hate two spaces
1 parent 83bf6cc commit 6c63c24

37 files changed

+3103
-3065
lines changed

src/org/klesun/deep_js_completion/completion_providers/DirnameConcatPvdr.scala

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,46 @@ import org.klesun.lang.DeepJsLang._
1010
import org.klesun.lang.ExplicitNull
1111

1212
/** provides path completion in __dirname + '/'; */
13-
class DirnameConcatPvdr extends CompletionProvider[CompletionParameters]
14-
{
15-
@throws(classOf[ExplicitNull])
16-
def getOptions(
17-
parameters: CompletionParameters,
18-
): It[LookupElementBuilder] = {
19-
val pos = parameters.getEditor.getCaretModel.getOffset
20-
val lit = Option(parameters.getOriginalPosition)
21-
.flatMap(leaf => Option(leaf.getParent))
22-
.flatMap(cast[JSLiteralExpression](_))
23-
.filter(lit => {
24-
val prevs = getPrevSiblings(lit).itr()
25-
.filter(s => !s.isInstanceOf[PsiWhiteSpace]).toList
26-
val isConcat = prevs.exists(op => op.getText.equals("+"))
27-
val isDirname = prevs.exists(left => left.getText.equals("__dirname"))
28-
isConcat && isDirname
29-
})
30-
.unl()
31-
val basePath = Option(lit.getContainingFile)
32-
.flatMap(f => Option(f.getVirtualFile))
33-
.flatMap(vf => Option(vf.getCanonicalPath))
34-
.unl().replaceAll("\\/[^\\/]*$", "")
35-
val relPath = substr(lit.getStringValue, 0, pos - lit.getTextOffset - 1)
36-
.replaceAll("\\/[^\\/]*$", "/")
37-
val caretPath = basePath + relPath
38-
val vf = notNull(LocalFileSystem.getInstance.findFileByPath(caretPath))
39-
vf.getChildren.map(f => f.getName).itr()
40-
.map(name => LookupElementBuilder.create(relPath + name)
41-
.withLookupString(relPath + name)
42-
.withIcon(PropNamePvdr.icon))
43-
}
13+
class DirnameConcatPvdr extends CompletionProvider[CompletionParameters] {
14+
@throws(classOf[ExplicitNull])
15+
def getOptions(
16+
parameters: CompletionParameters,
17+
): It[LookupElementBuilder] = {
18+
val pos = parameters.getEditor.getCaretModel.getOffset
19+
val lit = Option(parameters.getOriginalPosition)
20+
.flatMap(leaf => Option(leaf.getParent))
21+
.flatMap(cast[JSLiteralExpression](_))
22+
.filter(lit => {
23+
val prevs = getPrevSiblings(lit).itr()
24+
.filter(s => !s.isInstanceOf[PsiWhiteSpace]).toList
25+
val isConcat = prevs.exists(op => op.getText.equals("+"))
26+
val isDirname = prevs.exists(left => left.getText.equals("__dirname"))
27+
isConcat && isDirname
28+
})
29+
.unl()
30+
val basePath = Option(lit.getContainingFile)
31+
.flatMap(f => Option(f.getVirtualFile))
32+
.flatMap(vf => Option(vf.getCanonicalPath))
33+
.unl().replaceAll("\\/[^\\/]*$", "")
34+
val relPath = substr(lit.getStringValue, 0, pos - lit.getTextOffset - 1)
35+
.replaceAll("\\/[^\\/]*$", "/")
36+
val caretPath = basePath + relPath
37+
val vf = notNull(LocalFileSystem.getInstance.findFileByPath(caretPath))
38+
vf.getChildren.map(f => f.getName).itr()
39+
.map(name => LookupElementBuilder.create(relPath + name)
40+
.withLookupString(relPath + name)
41+
.withIcon(PropNamePvdr.icon))
42+
}
4443

45-
override def addCompletions(
46-
parameters: CompletionParameters,
47-
context: ProcessingContext,
48-
result: CompletionResultSet
49-
) = {
50-
try {
51-
getOptions(parameters).foreach(result.addElement)
52-
} catch {
53-
case nulled: ExplicitNull =>
54-
}
55-
}
44+
override def addCompletions(
45+
parameters: CompletionParameters,
46+
context: ProcessingContext,
47+
result: CompletionResultSet
48+
) = {
49+
try {
50+
getOptions(parameters).foreach(result.addElement)
51+
} catch {
52+
case nulled: ExplicitNull =>
53+
}
54+
}
5655
}

src/org/klesun/deep_js_completion/completion_providers/JsdocPvdr.scala

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,65 +18,65 @@ import org.klesun.deep_js_completion.entry.PathStrGoToDecl
1818
import org.klesun.deep_js_completion.resolvers.VarRes
1919

2020
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+
}
2626

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+
}
3333

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+
}
4040
}
4141

4242
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+
}
8282
}

0 commit comments

Comments
 (0)