Skip to content

Feature Request - ViewBinding Nav support #201

Description

@hikkidev

ViewBinding Navigation support

Goal

Provide navigation between Android layouts (res/layout/*.xml) and their usage through generated ViewBinding.java in Kotlin.

Scenarios

LSP From To
textDocument/definition type/import FooBarBinding (Kotlin) start of the layout XML file
textDocument/implementation type/import FooBarBinding (Kotlin) the generated *Binding.java class
textDocument/implementation tag <TextView>/<com.x.Custom> (XML) the view class definition
textDocument/references binding.field (Kotlin) all Kotlin usages of the field
textDocument/definition binding.field (Kotlin) @+id/field XML declaration
textDocument/references @+id/field (XML) all Kotlin usages of the field
Hover binding.field val field: <ViewType>

Resolution

  • Without a build — show error (build required)
  • After a build — real field names and types come from generated Java. Special case: a root-view field in bind() loses its R.id → recover resource_id by field name from XML.

Resolving the binding class for a position in a file

qualified, unqualified and contextual (like this, apply, it, etc)

Indexing basic

  • Open Kotlin (contains import *.databinding.*Binding): find generated Bindning.java -> resolve .xml layout and process them (async)
  • Open XML layout: -> idk; hard to resolve binding class
  • Change/Create XML in res/layout: index_layout_file (reindex)
  • Delete XML: cleanup
layout_file_to_binding_class(id) = camelCase,snake → Pascal + "Binding.java"
view_id_to_field(id) = camelCase, snake → camelCase
is_layout_xml_path(path) = path contains "/res/layout" and p endswith ".xml"

Skip Legacy

  • Data-binding
  • Kotlin synthetics (kotlinx.android.synthetic).
  • Resolution without a layout file present (a pure Java binding with no XML is not indexed)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions