Skip to content

Commit

Permalink
#7 Fix: null pointer on JSLiteralExpressionImpl.getValue
Browse files Browse the repository at this point in the history
GoTo string paths like './dir/file', even if it does not end with '.js'
  • Loading branch information
klesun committed Oct 25, 2018
1 parent bbe91d2 commit 98ab9b7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>lv.midiana.misc.idea-plugins.deep-js-completion</id>
<name>deep-js-completion</name>
<version>2018.10.18.001</version>
<version>2018.10.25.001</version>
<vendor email="safronevev@gmail.com" url="http://midiana.lv/entry/deep-js-completion">Klesun</vendor>

<description><![CDATA[
Expand All @@ -26,7 +26,8 @@ This plugin will be highly inspired by my other plugin, <a href="https://plugins
]]></description>

<change-notes><![CDATA[
<li>Fix: null pointer on JSRootConfiguration.getInstance</li>
<li>GoTo string paths like './dir/file', even if it does not end with '.js'</li>
<li>Fix: null pointer on JSLiteralExpressionImpl.getValue</li>
]]>
</change-notes>

Expand Down
4 changes: 2 additions & 2 deletions src/org/klesun/deep_js_completion/entry/PathStrGoToDecl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ object PathStrGoToDecl {
def getReferencedFile(relPath: String, caretFile: PsiFile): Option[PsiFile] = {
Option(caretFile.getContainingDirectory)
.flatMap(f => Option(f.getVirtualFile))
.map(f => f.getPath + "/" + relPath)
.map(f => f.getPath + "/" + relPath + (if (relPath.matches(".*\\.[a-zA-Z0-9]+$")) "" else ".js"))
.flatMap(fullPath => Option(LocalFileSystem.getInstance.findFileByPath(fullPath)))
.flatMap(f => Option(PsiManager.getInstance(caretFile.getProject).findFile(f)))
}

def getReferencedFile(expr: JSExpression): Option[PsiFile] = {
cast[JSLiteralExpressionImpl](expr)
.flatMap(lit => {
val relPath = lit.getValue.toString
val relPath = Option(lit.getValue).map(_.toString).getOrElse("")
if (relPath.startsWith("./") || relPath.startsWith("../")) {
Option(lit.getContainingFile)
.flatMap(f => getReferencedFile(relPath, f))
Expand Down
2 changes: 1 addition & 1 deletion tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let ssrLineNumbers = [];

var klesun = Klesun();
klesun.requires('./Tls.js').then = Tls =>
klesun.requires('./Tls').then = Tls =>
klesun.whenLoaded = () => (...ctorParams) => {
let tls = Tls();
// should suggest: opt, promise, http, mkDom, range, deepCopy
Expand Down

0 comments on commit 98ab9b7

Please sign in to comment.