Language Server Features
The XML Language Server (XMLLanguageServer) offers specialized support for Android XML files:
Context-Aware Completion
Intelligent suggestions based on file type (layout, manifest, drawable, etc.)
Android Attributes
Complete android: namespace attributes with value suggestions
Resource References
Auto-complete @string, @drawable, @color, and other resource references
Code Formatting
Automatic XML formatting with configurable indentation and line breaks
File Type Support
The XML LSP recognizes and provides specialized completion for different Android XML file types:Layout Files
Layout files inres/layout/ receive specialized completion:
- Attributes
- Resource Values
LayoutTagCompletionProvider and LayoutAttrCompletionProvider (source: xml/lsp/src/main/java/com/tom/rv2ide/lsp/xml/providers/completion/layout/)
AndroidManifest.xml
Specialized completion for manifest elements:AndroidManifest.xml
ManifestTagCompletionProvider, ManifestAttrCompletionProvider, and ManifestAttrValueCompletionProvider
Drawable XML Files
Completion for drawable resources (res/drawable/):
- Shape Drawables
- Layer List
- Vector Drawables
button_background.xml
DrawableTagTransformer to provide context-specific suggestions
Animation Files
Support for animation XML files:- View Animations
- Object Animators
fade_in.xml
AnimTagTransformer and AnimatorTagTransformer for type-specific completion
Menu Files
Completion for menu resources:main_menu.xml
MenuTagTransformer
Completion Providers
The XML LSP uses a provider pattern for different completion contexts:Tag Completion
Provides suggestions for XML element names:- LayoutTagCompletionProvider: Android View classes
- ManifestTagCompletionProvider: Manifest elements (activity, service, receiver, etc.)
- SimpleTagCompleter: Simple tag name completion
- QualifiedTagCompleter: Fully qualified class names
Attribute Completion
Suggests available attributes for a given element:- LayoutAttrCompletionProvider: View attributes
- ManifestAttrCompletionProvider: Manifest attributes
- CommonAttrCompletionProvider: Common XML attributes
- InheritingAttrCompletionProvider: Attributes inherited from parent tags
Attribute Value Completion
Provides value suggestions for attributes:- AttrValueCompletionProvider: Resource references, enum values, booleans
- ManifestAttrValueCompletionProvider: Manifest-specific values (permissions, features, etc.)
Code Formatting
The XML formatter (CodeFormatProvider) provides automatic formatting:
Formatting Options
Before and After Formatting
- Before
- After
XMLFormatter: Main formatting coordinatorDOMElementFormatter: Element formatting logicDOMAttributeFormatter: Attribute alignmentDOMTextFormatter: Text content formatting
Advanced Editing Features
Auto-Close Tags
TheAdvancedEditProvider handles automatic tag closing:
Attribute Quotes
Automatic quote insertion for attribute values:Resource Reference Completion
Type@ to trigger resource reference completion:
@string/- String resources@drawable/- Drawable resources@color/- Color resources@dimen/- Dimension resources@style/- Style resources@id/- View IDs@+id/- Define new ID@android:- Android framework resources
XML Parsing
The XML LSP uses Eclipse LemMinX DOM parser for robust XML parsing:- Error Recovery: Continue parsing despite syntax errors
- Node Location: Accurate position information for completions
- Namespace Support: Handle android:, app:, and tools: namespaces
Node Type Detection
The completion system detects context usingXmlUtils.getNodeType():
Configuration
Server Settings
Custom Settings
Apply custom settings to the XML server:Performance
Caching
The XML LSP caches parsed documents to improve performance:- Parse Cache: Stores DOM trees for recently accessed files
- Resource Cache: Caches available resources from R class
- Attribute Cache: Stores attribute definitions for view types
Prefix Matching
Completion is triggered only when a meaningful prefix is typed:Limitations
Troubleshooting
Completion Not Working
If XML completion stops working:- Check the file is in a recognized directory (
res/layout/,res/drawable/, etc.) - Ensure the XML file has a valid XML declaration
- Verify the namespace declarations are correct
- Check that the project has been synced
Formatting Issues
If formatting produces unexpected results:- Check for unclosed tags in the XML
- Verify the XML is well-formed (balanced tags)
- Adjust formatting options in settings
Resource References Not Completing
If@string/ and other resource references don’t complete:
- Ensure resources are defined in appropriate XML files
- Check that the R class has been generated (build the project)
- Verify the module dependencies include the resources
API Reference
XMLLanguageServer
Main server interface:XmlCompletionProvider
Completion implementation:CodeFormatProvider
Formatting implementation:Related Documentation
Java Support
Learn about Java language features
Kotlin Support
Explore Kotlin language capabilities
Project Management
Manage Android resources and projects
UI Designer
Visual layout editor