Skip to content

Commit

Permalink
allow trailing slashes in local paths (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov authored Jan 25, 2025
1 parent f3c311a commit 1c12de7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.move.toml

import com.intellij.psi.ElementManipulators
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiReferenceProvider
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference
Expand All @@ -9,14 +10,22 @@ import org.toml.lang.psi.TomlLiteral
import org.toml.lang.psi.ext.TomlLiteralKind
import org.toml.lang.psi.ext.kind

class MoveTomlLocalPathReferenceProvider : PsiReferenceProvider() {
class MoveTomlLocalPathReferenceProvider: PsiReferenceProvider() {
override fun getReferencesByElement(
element: PsiElement,
context: ProcessingContext
): Array<FileReference> {
val kind = (element as? TomlLiteral)?.kind ?: return emptyArray()
if (kind !is TomlLiteralKind.String) return emptyArray()

return FileReferenceSet(element).allReferences
val valueRange = ElementManipulators.getValueTextRange(element)
return FileReferenceSet(
valueRange.substring(element.text),
element,
valueRange.startOffset,
this,
false,
false
).allReferences
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,18 @@ class MoveTomlUnresolvedPathInspectionTest:
""")
sources {}
})

fun `test no error with extra slash at the end`() = checkByFileTree(code = {
namedMoveToml("Root", """
[dependencies]
local = "./child/"
<caret>
""")
sources {}
dir("child") {
namedMoveToml("Child")
sources { }
}
})
}

0 comments on commit 1c12de7

Please sign in to comment.