mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-12-23 09:19:21 +00:00
Remove extension when completing \include
This commit is contained in:
parent
14f5507b2f
commit
a980d782fa
7 changed files with 29 additions and 11 deletions
|
|
@ -1,6 +1,5 @@
|
|||
package texlab
|
||||
|
||||
import com.sun.jndi.toolkit.url.Uri
|
||||
import org.eclipse.lsp4j.*
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either
|
||||
import org.eclipse.lsp4j.jsonrpc.services.JsonDelegate
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ class TextDocumentServiceImpl(private val workspace: Workspace) : CustomTextDocu
|
|||
AggregateCompletionProvider(
|
||||
includeGraphicsProvider,
|
||||
LatexIncludeProvider(workspace),
|
||||
LatexInputProvider(workspace),
|
||||
LatexBibliographyProvider(workspace),
|
||||
LatexClassImportProvider(resolver),
|
||||
LatexPackageImportProvider(resolver),
|
||||
|
|
|
|||
|
|
@ -9,8 +9,9 @@ import texlab.syntax.latex.LatexCommandSyntax
|
|||
import java.net.URI
|
||||
import java.nio.file.Paths
|
||||
|
||||
abstract class IncludeProvider<T>(private val workspace: Workspace,
|
||||
private val documentClass: Class<T>) : LatexArgumentProvider() where T : Document {
|
||||
abstract class DocumentProvider<T>(private val workspace: Workspace,
|
||||
private val documentClass: Class<T>,
|
||||
private val includeExtension: Boolean) : LatexArgumentProvider() where T : Document {
|
||||
override val argumentIndex: Int = 0
|
||||
|
||||
override fun complete(request: CompletionRequest, command: LatexCommandSyntax): List<CompletionItem> {
|
||||
|
|
@ -23,7 +24,16 @@ abstract class IncludeProvider<T>(private val workspace: Workspace,
|
|||
|
||||
private fun relativize(base: URI, relative: URI): String {
|
||||
val pathAbsolute = Paths.get(relative)
|
||||
val pathBase = Paths.get(base).parent
|
||||
return pathBase.relativize(pathAbsolute).toString().replace('\\', '/')
|
||||
var path = Paths.get(base)
|
||||
.parent
|
||||
.relativize(pathAbsolute)
|
||||
.toString()
|
||||
.replace('\\', '/')
|
||||
|
||||
if (!includeExtension && path.contains('.')) {
|
||||
path = path.substring(0, path.lastIndexOf('.'))
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,6 @@ import texlab.BibtexDocument
|
|||
import texlab.Workspace
|
||||
|
||||
class LatexBibliographyProvider(workspace: Workspace) :
|
||||
IncludeProvider<BibtexDocument>(workspace, BibtexDocument::class.java) {
|
||||
DocumentProvider<BibtexDocument>(workspace, BibtexDocument::class.java, true) {
|
||||
override val commandNames: List<String> = listOf("\\bibliography", "\\addbibresource")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import texlab.LatexDocument
|
|||
import texlab.Workspace
|
||||
|
||||
class LatexIncludeProvider(workspace: Workspace) :
|
||||
IncludeProvider<LatexDocument>(workspace, LatexDocument::class.java) {
|
||||
override val commandNames: List<String> = listOf("\\include", "\\input")
|
||||
DocumentProvider<LatexDocument>(workspace, LatexDocument::class.java, false) {
|
||||
override val commandNames: List<String> = listOf("\\include")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package texlab.completion.latex
|
||||
|
||||
import texlab.LatexDocument
|
||||
import texlab.Workspace
|
||||
|
||||
class LatexInputProvider(workspace: Workspace) :
|
||||
DocumentProvider<LatexDocument>(workspace, LatexDocument::class.java, true) {
|
||||
override val commandNames: List<String> = listOf("\\input")
|
||||
}
|
||||
|
|
@ -8,13 +8,13 @@ class LatexIncludeProviderTests {
|
|||
@Test
|
||||
fun `it should exclude files that are already included`() {
|
||||
val builder = WorkspaceBuilder()
|
||||
.document("foo.tex", "\\include{bar.tex}\n\\include{}")
|
||||
.document("foo.tex", "\\include{bar}\n\\include{}")
|
||||
.document("bar.tex", "")
|
||||
.document("baz.tex", "")
|
||||
|
||||
val provider = LatexIncludeProvider(builder.workspace)
|
||||
|
||||
val expected = arrayOf("baz.tex")
|
||||
val expected = arrayOf("baz")
|
||||
val actual = provider
|
||||
.complete(builder.completion("foo.tex", 1, 9))
|
||||
.map { it.label }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue