Skip to content

Commit 08a9901

Browse files
authored
Merge pull request #3409 from Hannah-Sten/TEX-153
Fix bug with completion of file path arguments when text already present
2 parents ab9937d + b6569ae commit 08a9901

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

.github/actions/insert-youtrack-link/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ inputs:
1111
description: 'Secret repository token'
1212
required: true
1313
runs:
14-
using: node16
14+
using: node20
1515
main: index.js

src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexPathProviderBase.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import nl.hannahsten.texifyidea.psi.LatexRequiredParam
2121
import nl.hannahsten.texifyidea.util.expandCommandsOnce
2222
import nl.hannahsten.texifyidea.util.files.findRootFile
2323
import nl.hannahsten.texifyidea.util.files.isLatexFile
24+
import nl.hannahsten.texifyidea.util.replaceAfterFrom
2425
import java.io.File
2526
import java.util.regex.Pattern
2627

@@ -176,7 +177,8 @@ abstract class LatexPathProviderBase : CompletionProvider<CompletionParameters>(
176177
val icon = TexifyIcons.getIconFromExtension(foundFile.extension, default = FILE)
177178
resultSet?.addElement(
178179
LookupElementBuilder.create(baseDir + foundFile.name)
179-
.withPresentableText(foundFile.presentableName)
180+
.withPresentableText(foundFile.nameWithoutExtension)
181+
.withTailText(".${foundFile.extension}", true)
180182
.withInsertHandler(
181183
CompositeHandler(
182184
LatexReferenceInsertHandler(),
@@ -233,7 +235,7 @@ abstract class LatexPathProviderBase : CompletionProvider<CompletionParameters>(
233235
*
234236
* This does the following:
235237
* - Removes any start '{' and ending '}'
236-
* - Remove 'IntelliJIdeaRulezz'
238+
* - Remove 'IntelliJIdeaRulezzz'
237239
* - Removes any arguments before the last one (separated by ',')
238240
* - Remove starting './'
239241
* - Prevent '//' (removes the first '/')
@@ -244,8 +246,10 @@ abstract class LatexPathProviderBase : CompletionProvider<CompletionParameters>(
244246
// When the last parameter is autocompleted, parameters before that may also be present in
245247
// autocompleteText so we split on commas and take the last one. If it is not the last
246248
// parameter, no commas will be present so the split will do nothing.
247-
result = result.replace("IntellijIdeaRulezzz", "")
248-
.split(",").last()
249+
result = result.split(",").last()
250+
251+
// Remove everything that comes after and including IntellijIdeaRulezzz, as that is the dummy for the caret.
252+
result = result.replaceAfterFrom("IntellijIdeaRulezzz", "")
249253

250254
// Prevent double ./
251255
if (result.startsWith("./")) {

src/nl/hannahsten/texifyidea/util/Strings.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ fun String.removeAll(vararg strings: String): String {
154154
*/
155155
fun String.remove(string: String): String = this.replace(string, "")
156156

157+
/**
158+
* Replace everything after [string] - including [string] - from [this].
159+
*/
160+
fun String.replaceAfterFrom(string: String, replacement: String) = this.replaceAfter(string, replacement).remove(string)
161+
157162
/**
158163
* Formats the string as a valid filename, removing not-allowed characters, in TeX-style with - as separator.
159164
*/

test/nl/hannahsten/texifyidea/completion/LatexPathCompletionRelativeToRootFile.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package nl.hannahsten.texifyidea.completion
22

33
import com.intellij.codeInsight.completion.CompletionType
4+
import com.intellij.codeInsight.lookup.Lookup
45
import com.intellij.testFramework.fixtures.BasePlatformTestCase
56
import nl.hannahsten.texifyidea.file.LatexFileType
67

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

41+
fun `test completion for partly entered filename`() {
42+
myFixture.configureByText(LatexFileType, """\input{i<caret>.tex}""")
43+
44+
myFixture.complete(CompletionType.BASIC)
45+
myFixture.finishLookup(Lookup.NORMAL_SELECT_CHAR)
46+
47+
myFixture.checkResult("""\input{inputted.tex}""")
48+
}
49+
50+
fun `test tab completion for partly entered filename`() {
51+
myFixture.configureByText(LatexFileType, """\input{i<caret>.tex}""")
52+
53+
myFixture.complete(CompletionType.BASIC)
54+
myFixture.finishLookup(Lookup.REPLACE_SELECT_CHAR)
55+
56+
myFixture.checkResult("""\input{inputted}""")
57+
}
58+
4059
fun `test completion in included file from subdirectory for files in main dir`() {
4160
myFixture.configureByFile("nest/bird2.tex")
4261

0 commit comments

Comments
 (0)