mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix: rename CompletionItem.label to CompletionItem.ideLable to avoid name shadowing
This commit is contained in:
@@ -74,7 +74,7 @@ class CompletionListAdapter : EditorCompletionAdapter() {
|
||||
convertView?.let { LayoutCompletionItemBinding.bind(it) }
|
||||
?: LayoutCompletionItemBinding.inflate(LayoutInflater.from(context), parent, false)
|
||||
val item = getItem(position) as LspCompletionItem
|
||||
val label = item.getLabel()
|
||||
val label = item.ideLabel
|
||||
val desc = item.detail
|
||||
var type: String? = item.completionKind.toString()
|
||||
val header = if (type!!.isEmpty()) "O" else type[0].toString()
|
||||
|
||||
+1
-1
@@ -383,7 +383,7 @@ public class GroovyAutoComplete {
|
||||
|
||||
private CompletionItem createCompletionItem(String itemLabel) {
|
||||
CompletionItem item = new CompletionItem();
|
||||
item.setLabel(itemLabel);
|
||||
item.setIdeLabel(itemLabel);
|
||||
item.setDetail("");
|
||||
item.setInsertText(itemLabel);
|
||||
item.setIdeSortText("0" + itemLabel);
|
||||
|
||||
+9
-9
@@ -151,7 +151,7 @@ abstract class IJavaCompletionProvider(
|
||||
abortIfCancelled()
|
||||
abortCompletionIfCancelled()
|
||||
val item = JavaCompletionItem()
|
||||
item.setLabel(keyword)
|
||||
item.ideLabel = keyword
|
||||
item.completionKind = KEYWORD
|
||||
item.detail = "keyword"
|
||||
item.ideSortText = keyword
|
||||
@@ -170,10 +170,10 @@ abstract class IJavaCompletionProvider(
|
||||
abortCompletionIfCancelled()
|
||||
val first = overloads[0]
|
||||
val item = JavaCompletionItem()
|
||||
item.setLabel(first.simpleName.toString())
|
||||
item.ideLabel = first.simpleName.toString()
|
||||
item.completionKind = CompletionItemKind.METHOD
|
||||
item.detail = printMethodDetail(first)
|
||||
item.ideSortText = item.label.toString()
|
||||
item.ideSortText = item.ideLabel
|
||||
item.matchLevel = matchLevel
|
||||
item.overrideTypeText = EditHelper.printType(first.returnType)
|
||||
val data = data(task, first, overloads.size)
|
||||
@@ -221,11 +221,11 @@ abstract class IJavaCompletionProvider(
|
||||
abortIfCancelled()
|
||||
abortCompletionIfCancelled()
|
||||
val item = JavaCompletionItem()
|
||||
item.setLabel(element.simpleName.toString())
|
||||
item.ideLabel = element.simpleName.toString()
|
||||
item.completionKind = kind(element)
|
||||
item.detail = element.toString()
|
||||
item.data = data(task, element, 1)
|
||||
item.ideSortText = item.label.toString()
|
||||
item.ideSortText = item.ideLabel
|
||||
item.matchLevel = matchLevel
|
||||
|
||||
if (element is VariableElement) {
|
||||
@@ -251,10 +251,10 @@ abstract class IJavaCompletionProvider(
|
||||
abortIfCancelled()
|
||||
abortCompletionIfCancelled()
|
||||
val item = JavaCompletionItem()
|
||||
item.setLabel(simpleName(className).toString())
|
||||
item.ideLabel = simpleName(className).toString()
|
||||
item.completionKind = CompletionItemKind.CLASS
|
||||
item.detail = packageName(className).toString()
|
||||
item.ideSortText = item.label.toString()
|
||||
item.ideSortText = item.ideLabel
|
||||
item.matchLevel = matchLevel
|
||||
item.data = ClassCompletionData(className)
|
||||
|
||||
@@ -284,7 +284,7 @@ abstract class IJavaCompletionProvider(
|
||||
packageName = " "
|
||||
}
|
||||
return JavaCompletionItem().apply {
|
||||
setLabel(simpleName)
|
||||
this.ideLabel = simpleName
|
||||
this.detail = packageName
|
||||
this.insertText = simpleName
|
||||
this.completionKind = MODULE
|
||||
@@ -300,7 +300,7 @@ abstract class IJavaCompletionProvider(
|
||||
indent: Int
|
||||
): CompletionItem {
|
||||
return JavaCompletionItem().apply {
|
||||
this.label = snippet.prefix
|
||||
this.ideLabel = snippet.prefix
|
||||
this.detail = snippet.description
|
||||
this.completionKind = CompletionItemKind.SNIPPET
|
||||
this.matchLevel = matchLevel
|
||||
|
||||
+2
-2
@@ -169,10 +169,10 @@ class ScopeCompletionProvider(
|
||||
abortCompletionIfCancelled()
|
||||
|
||||
val item = JavaCompletionItem()
|
||||
item.setLabel(methodSpec.name)
|
||||
item.ideLabel = methodSpec.name
|
||||
item.completionKind = com.itsaky.androidide.lsp.models.CompletionItemKind.METHOD
|
||||
item.detail = method.returnType.toString() + " " + method
|
||||
item.ideSortText = item.label.toString()
|
||||
item.ideSortText = item.ideLabel
|
||||
item.insertText = insertText
|
||||
item.insertTextFormat = SNIPPET
|
||||
item.snippetDescription = describeSnippet(partial)
|
||||
|
||||
+1
-1
@@ -89,6 +89,6 @@ class JavaCompletionProviderTest {
|
||||
.complete(
|
||||
CompletionParams(pos, JavaLSPTest.file!!, ICancelChecker.NOOP).apply { prefix = "" })
|
||||
.items
|
||||
.map { it.label }
|
||||
.map { it.ideLabel }
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ class CompletionItemComparator {
|
||||
static int compare(CompletionItem one, CompletionItem two) {
|
||||
return Comparator.comparing(item -> ((CompletionItem) item).getMatchLevel().ordinal())
|
||||
.thenComparing(item -> ((CompletionItem) item).getIdeSortText())
|
||||
.thenComparing(item -> ((CompletionItem) item).label)
|
||||
.thenComparing(item -> ((CompletionItem) item).getIdeLabel())
|
||||
.compare(one, two);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ open class CompletionResult(items: Collection<CompletionItem>) {
|
||||
): CompletionResult {
|
||||
val newItems = src.items.toMutableList()
|
||||
newItems.forEach(map)
|
||||
newItems.removeIf { !it.label.startsWith(partial) }
|
||||
newItems.removeIf { !it.ideLabel.startsWith(partial) }
|
||||
return CompletionResult(newItems)
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ open class CompletionResult(items: Collection<CompletionItem>) {
|
||||
}
|
||||
|
||||
open class CompletionItem(
|
||||
@JvmField var label: String,
|
||||
var ideLabel: String,
|
||||
var detail: String,
|
||||
insertText: String?,
|
||||
insertTextFormat: InsertTextFormat?,
|
||||
@@ -133,12 +133,12 @@ open class CompletionItem(
|
||||
var data: ICompletionData?,
|
||||
var editHandler: IEditHandler = DefaultEditHandler()
|
||||
) :
|
||||
io.github.rosemoe.sora.lang.completion.CompletionItem(label, detail), Comparable<CompletionItem> {
|
||||
io.github.rosemoe.sora.lang.completion.CompletionItem(ideLabel, detail), Comparable<CompletionItem> {
|
||||
|
||||
var ideSortText: String? = sortText
|
||||
get() {
|
||||
if (field == null) {
|
||||
return label.toString()
|
||||
return ideLabel
|
||||
}
|
||||
|
||||
return field
|
||||
@@ -147,7 +147,7 @@ open class CompletionItem(
|
||||
var insertText: String = insertText ?: ""
|
||||
get() {
|
||||
if (field.isEmpty()) {
|
||||
return this.label.toString()
|
||||
return this.ideLabel
|
||||
}
|
||||
|
||||
return field
|
||||
@@ -208,12 +208,6 @@ open class CompletionItem(
|
||||
}
|
||||
}
|
||||
|
||||
fun setLabel(label: String) {
|
||||
this.label = label
|
||||
}
|
||||
|
||||
fun getLabel(): String = this.label as String
|
||||
|
||||
override fun performCompletion(editor: CodeEditor, text: Content, position: CharPosition) {
|
||||
editHandler.performEdits(this, editor, text, position.line, position.column, position.index)
|
||||
}
|
||||
@@ -230,7 +224,7 @@ open class CompletionItem(
|
||||
if (this === other) return true
|
||||
if (other !is CompletionItem) return false
|
||||
|
||||
if (label != other.label) return false
|
||||
if (ideLabel != other.ideLabel) return false
|
||||
if (detail != other.detail) return false
|
||||
if (command != other.command) return false
|
||||
if (completionKind != other.completionKind) return false
|
||||
@@ -248,7 +242,7 @@ open class CompletionItem(
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = label.hashCode()
|
||||
var result = ideLabel.hashCode()
|
||||
result = 31 * result + detail.hashCode()
|
||||
result = 31 * result + (command?.hashCode() ?: 0)
|
||||
result = 31 * result + completionKind.hashCode()
|
||||
@@ -265,7 +259,7 @@ open class CompletionItem(
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "CompletionItem(label='$label', detail='$detail', command=$command, kind=$completionKind, matchLevel=$matchLevel, additionalTextEdits=$additionalTextEdits, data=$data, sortText=$ideSortText, insertText='$insertText', insertTextFormat=$insertTextFormat, editHandler=$editHandler, additionalEditHandler=$additionalEditHandler, overrideTypeText=$overrideTypeText)"
|
||||
return "CompletionItem(label='$ideLabel', detail='$detail', command=$command, kind=$completionKind, matchLevel=$matchLevel, additionalTextEdits=$additionalTextEdits, data=$data, sortText=$ideSortText, insertText='$insertText', insertTextFormat=$insertTextFormat, editHandler=$editHandler, additionalEditHandler=$additionalEditHandler, overrideTypeText=$overrideTypeText)"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -143,9 +143,9 @@ abstract class IXmlCompletionProvider(private val provider: ICompletionProvider)
|
||||
isPlatformWidget: Boolean = false
|
||||
): CompletionItem =
|
||||
CompletionItem().apply {
|
||||
this.label = simpleName
|
||||
this.ideLabel = simpleName
|
||||
this.detail = qualifiedName
|
||||
this.ideSortText = label.toString()
|
||||
this.ideSortText = ideLabel
|
||||
this.insertText = if (isPlatformWidget) simpleName else qualifiedName
|
||||
this.insertTextFormat = PLAIN_TEXT
|
||||
this.editHandler = TagEditHandler()
|
||||
@@ -178,13 +178,13 @@ abstract class IXmlCompletionProvider(private val provider: ICompletionProvider)
|
||||
|
||||
val title = "$prefix${attr.name.entry!!}"
|
||||
val insertText = if (hasNamespace) attr.name.entry!! else title
|
||||
this.label = title
|
||||
this.ideLabel = title
|
||||
this.completionKind = FIELD
|
||||
this.detail = "From package '$resPkg'"
|
||||
this.insertText = "$insertText=\"$0\""
|
||||
this.insertTextFormat = SNIPPET
|
||||
this.snippetDescription = describeSnippet(partial)
|
||||
this.ideSortText = label.toString()
|
||||
this.ideSortText = ideLabel
|
||||
this.matchLevel = matchLevel
|
||||
this.command = Command("Trigger completion request", Command.TRIGGER_COMPLETION)
|
||||
}
|
||||
@@ -215,7 +215,7 @@ abstract class IXmlCompletionProvider(private val provider: ICompletionProvider)
|
||||
|
||||
val text = sb.toString()
|
||||
return CompletionItem().apply {
|
||||
this.label = text
|
||||
this.ideLabel = text
|
||||
this.detail = "From package '$pck'"
|
||||
this.completionKind = VALUE
|
||||
this.overrideTypeText = type.uppercase()
|
||||
@@ -240,7 +240,7 @@ abstract class IXmlCompletionProvider(private val provider: ICompletionProvider)
|
||||
matchLevel: MatchLevel
|
||||
): CompletionItem {
|
||||
return CompletionItem().apply {
|
||||
this.label = name
|
||||
this.ideLabel = name
|
||||
this.detail = if (pck.isBlank()) "" else "From package '$pck'"
|
||||
this.completionKind = VALUE
|
||||
this.ideSortText = "000$name"
|
||||
|
||||
@@ -26,6 +26,6 @@ import com.itsaky.androidide.lsp.models.CompletionItem
|
||||
interface CompletionHelper {
|
||||
|
||||
fun complete(
|
||||
transform: (CompletionItem) -> CharSequence = { it.label }
|
||||
transform: (CompletionItem) -> CharSequence = { it.ideLabel }
|
||||
): Pair<Boolean, List<CharSequence>>
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class CompletionHelperImpl : CompletionHelper {
|
||||
val result = server.complete(createCompletionParams)
|
||||
result.isIncomplete to
|
||||
result.items
|
||||
.filter { it.label != null }
|
||||
.filter { it.ideLabel.isNotBlank() }
|
||||
.map { transform(it) }
|
||||
.filter { it.isNotBlank() }
|
||||
.toList()
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ internal class ValueCompletionProvider(
|
||||
if (result.isIncomplete) "(incomplete)" else "",
|
||||
)
|
||||
|
||||
onComplete(result.items.mapNotNull { it.label?.toString() })
|
||||
onComplete(result.items.map { it.ideLabel })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user