Skip to content

Commit

Permalink
Merge pull request #3409 from Hannah-Sten/TEX-153
Browse files Browse the repository at this point in the history
Fix bug with completion of file path arguments when text already present
  • Loading branch information
PHPirates authored Jan 28, 2024
2 parents ab9937d + b6569ae commit 08a9901
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/actions/insert-youtrack-link/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ inputs:
description: 'Secret repository token'
required: true
runs:
using: node16
using: node20
main: index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import nl.hannahsten.texifyidea.psi.LatexRequiredParam
import nl.hannahsten.texifyidea.util.expandCommandsOnce
import nl.hannahsten.texifyidea.util.files.findRootFile
import nl.hannahsten.texifyidea.util.files.isLatexFile
import nl.hannahsten.texifyidea.util.replaceAfterFrom
import java.io.File
import java.util.regex.Pattern

Expand Down Expand Up @@ -176,7 +177,8 @@ abstract class LatexPathProviderBase : CompletionProvider<CompletionParameters>(
val icon = TexifyIcons.getIconFromExtension(foundFile.extension, default = FILE)
resultSet?.addElement(
LookupElementBuilder.create(baseDir + foundFile.name)
.withPresentableText(foundFile.presentableName)
.withPresentableText(foundFile.nameWithoutExtension)
.withTailText(".${foundFile.extension}", true)
.withInsertHandler(
CompositeHandler(
LatexReferenceInsertHandler(),
Expand Down Expand Up @@ -233,7 +235,7 @@ abstract class LatexPathProviderBase : CompletionProvider<CompletionParameters>(
*
* This does the following:
* - Removes any start '{' and ending '}'
* - Remove 'IntelliJIdeaRulezz'
* - Remove 'IntelliJIdeaRulezzz'
* - Removes any arguments before the last one (separated by ',')
* - Remove starting './'
* - Prevent '//' (removes the first '/')
Expand All @@ -244,8 +246,10 @@ abstract class LatexPathProviderBase : CompletionProvider<CompletionParameters>(
// When the last parameter is autocompleted, parameters before that may also be present in
// autocompleteText so we split on commas and take the last one. If it is not the last
// parameter, no commas will be present so the split will do nothing.
result = result.replace("IntellijIdeaRulezzz", "")
.split(",").last()
result = result.split(",").last()

// Remove everything that comes after and including IntellijIdeaRulezzz, as that is the dummy for the caret.
result = result.replaceAfterFrom("IntellijIdeaRulezzz", "")

// Prevent double ./
if (result.startsWith("./")) {
Expand Down
5 changes: 5 additions & 0 deletions src/nl/hannahsten/texifyidea/util/Strings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ fun String.removeAll(vararg strings: String): String {
*/
fun String.remove(string: String): String = this.replace(string, "")

/**
* Replace everything after [string] - including [string] - from [this].
*/
fun String.replaceAfterFrom(string: String, replacement: String) = this.replaceAfter(string, replacement).remove(string)

/**
* Formats the string as a valid filename, removing not-allowed characters, in TeX-style with - as separator.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nl.hannahsten.texifyidea.completion

import com.intellij.codeInsight.completion.CompletionType
import com.intellij.codeInsight.lookup.Lookup
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import nl.hannahsten.texifyidea.file.LatexFileType

Expand Down Expand Up @@ -37,6 +38,24 @@ class LatexPathCompletionRelativeToRootFile : BasePlatformTestCase() {
assert(result.any { it.lookupString == "inputted.tex" })
}

fun `test completion for partly entered filename`() {
myFixture.configureByText(LatexFileType, """\input{i<caret>.tex}""")

myFixture.complete(CompletionType.BASIC)
myFixture.finishLookup(Lookup.NORMAL_SELECT_CHAR)

myFixture.checkResult("""\input{inputted.tex}""")
}

fun `test tab completion for partly entered filename`() {
myFixture.configureByText(LatexFileType, """\input{i<caret>.tex}""")

myFixture.complete(CompletionType.BASIC)
myFixture.finishLookup(Lookup.REPLACE_SELECT_CHAR)

myFixture.checkResult("""\input{inputted}""")
}

fun `test completion in included file from subdirectory for files in main dir`() {
myFixture.configureByFile("nest/bird2.tex")

Expand Down

0 comments on commit 08a9901

Please sign in to comment.