Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow trailing slashes in local paths #275

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { }
}
})
}
Loading