Fixed: Incorrect (incomplete) qualified tag name insertion

This commit is contained in:
Akash Yadav
2022-09-19 21:22:50 +05:30
parent d67adbec67
commit fc86ad5976
7 changed files with 65 additions and 16 deletions
@@ -88,6 +88,7 @@ import java.util.concurrent.CompletableFuture;
import io.github.rosemoe.sora.event.ContentChangeEvent;
import io.github.rosemoe.sora.lang.EmptyLanguage;
import io.github.rosemoe.sora.lang.Language;
import io.github.rosemoe.sora.text.LineSeparator;
import io.github.rosemoe.sora.widget.component.Magnifier;
/**
@@ -115,6 +116,7 @@ public class CodeEditorView extends FrameLayout {
this.binding.editor.getProps().autoCompletionOnComposing = true;
this.binding.editor.setDividerWidth(SizeUtils.dp2px(1));
this.binding.editor.setColorScheme(new SchemeAndroidIDE());
this.binding.editor.setLineSeparator(LineSeparator.LF);
this.binding.editor.subscribeEvent(
ContentChangeEvent.class, ((event, unsubscribe) -> handleContentChange(event)));
@@ -20,4 +20,54 @@ package com.itsaky.androidide.aapt.logging
import com.android.utils.StdLogger
import com.android.utils.StdLogger.Level.VERBOSE
object IDELogger : StdLogger(VERBOSE)
object IDELogger : StdLogger(VERBOSE) {
var enabled = false
override fun error(t: Throwable?, errorFormat: String?, vararg args: Any?) {
if (!enabled) {
return
}
super.error(t, errorFormat, *args)
}
override fun warning(warningFormat: String?, vararg args: Any?) {
if (!enabled) {
return
}
super.warning(warningFormat, *args)
}
override fun quiet(msgFormat: String?, vararg args: Any?) {
if (!enabled) {
return
}
super.quiet(msgFormat, *args)
}
override fun lifecycle(msgFormat: String?, vararg args: Any?) {
if (!enabled) {
return
}
super.lifecycle(msgFormat, *args)
}
override fun info(msgFormat: String?, vararg args: Any?) {
if (!enabled) {
return
}
super.info(msgFormat, *args)
}
override fun verbose(msgFormat: String?, vararg args: Any?) {
if (!enabled) {
return
}
super.verbose(msgFormat, *args)
}
}
@@ -61,11 +61,11 @@ import com.itsaky.androidide.utils.ILogger
import com.itsaky.androidide.utils.StopWatch
import com.itsaky.xml.INamespace
import io.github.rosemoe.sora.text.ContentReference
import org.eclipse.lemminx.dom.DOMParser
import org.eclipse.lemminx.uriresolver.URIResolverExtensionManager
import java.io.IOException
import java.io.Reader
import kotlin.io.path.name
import org.eclipse.lemminx.dom.DOMParser
import org.eclipse.lemminx.uriresolver.URIResolverExtensionManager
/**
* Completion provider for XML files.
@@ -126,14 +126,9 @@ class XmlCompletionProvider(settings: IServerSettings) :
}
private fun toString(contents: CharSequence): String {
val reader = getReader(contents)
val text = reader.readText()
try {
reader.close()
} catch (e: IOException) {
log.warn("Unable to close char sequence reader", e)
return getReader(contents).use {
it.readText()
}
return text
}
private fun getReader(contents: CharSequence): Reader =
@@ -31,6 +31,7 @@ import com.itsaky.androidide.lsp.models.CompletionItemKind.FIELD
import com.itsaky.androidide.lsp.models.CompletionItemKind.VALUE
import com.itsaky.androidide.lsp.models.CompletionParams
import com.itsaky.androidide.lsp.models.CompletionResult
import com.itsaky.androidide.lsp.models.InsertTextFormat.PLAIN_TEXT
import com.itsaky.androidide.lsp.models.InsertTextFormat.SNIPPET
import com.itsaky.androidide.lsp.models.MatchLevel
import com.itsaky.androidide.lsp.xml.edits.QualifiedValueEditHandler
@@ -142,6 +143,8 @@ abstract class IXmlCompletionProvider(private val provider: ICompletionProvider)
this.label = simpleName
this.detail = qualifiedName
this.sortText = label.toString()
this.insertText = qualifiedName
this.insertTextFormat = PLAIN_TEXT
this.editHandler = TagEditHandler()
this.matchLevel = matchLevel
this.kind = CLASS
@@ -100,14 +100,14 @@ object XmlUtils {
fun getPrefix(parsed: DOMDocument, index: Int, type: NodeType?): String? {
val text = parsed.text
when (type) {
return when (type) {
TAG -> {
val nodeAt = parsed.findNodeAt(index) ?: return null
return text.substring(nodeAt.start, index)
text.substring(nodeAt.start, index)
}
ATTRIBUTE -> {
val attr = parsed.findAttrAt(index) ?: return null
return text.substring(attr.start, index)
text.substring(attr.start, index)
}
ATTRIBUTE_VALUE -> {
val attrAt = parsed.findAttrAt(index) ?: return null
@@ -115,9 +115,9 @@ object XmlUtils {
if (prefix.contains("|")) {
prefix = prefix.substring(prefix.lastIndexOf('|') + 1)
}
return prefix
prefix
}
else -> return "<this-will-not-match>"
else -> "<this-will-not-match>"
}
}
@@ -142,7 +142,6 @@ class AttributeValueCompletionTest : CompletionHelper by CompletionHelperImpl()
}
@Test // prefix: '@com.itsaky.test.app:string/ap' // for attribute 'android:text'
// TestAttrValueWithQualifiedRefWithIncompleteType
fun `test value completion with qualified reference prefix (test with custom package not android)`() {
XMLLSPTest.apply {
openFile("../res/layout/TestAttrValueWithQualifiedRefPrefix2")
Binary file not shown.