In June 2023, I was selected for Linux Foundation mentorship to contribute to the Solang compiler . Solang is a Solidty compiler that targets Solana and Polkadot. It is written in Rust and uses LLVM as the backend. The mentorship focused on enriching the language server’s functionalities, which would make for a better development experience.
Working
The language server operates in conjunction with the compiler, using the Abstract Syntax Tree (AST) it generates. The language server traverses the AST and extracts information like location, type, scope information, among other things, of various symbols present in the source code. This is repeated everytime there are changes in the source code. The extracted information is later used to serve user requests like goto-definition, rename etc.
Code for language server can be found here .
Features
Here are the features offered by the language server. Descriptions of these features are accompanied by videos demonstrating their use, available under the Video tab.
Go to Definition
Returns the definition of a variable or a type defined in user code.
Go to Declaration
Returns a list of methods that the given method overrides.
Go to Implementation
Returns a list of methods defined for the given contract.
Go to Type Definition
Returns the type of the given symbol (variable, struct field, contract method etc).
Go to References
Returns a list of uses of the given symbol.
Rename
Renames the given symbol.
Code Completion
Offers suggestions to the user based on contextual information and lexical scoping. Pressing . yields the properties (such as struct fields, enum variants, contract methods etc.) associated with the preceding symbol.
Format Code
Hovers
Displays information about the symbol under the cursor.
Improvements
Here are some ideas for enhancements:
- The language server relies on compiler’s parser to extract information from the source code. However, the parser tends to prematurely halt in the presence of errors and may not parse the entire program. This hinders language server’s ability to offer information or suggestions to the user during code editing. We need to make the parser more resilient to errors.
- Incorporate missing source code locations of various symbols in the parse tree.
Takeaways
Contributing to open source projects can be a very fulfilling and enjoyable experience. It helps one foster connections with like-minded individuals and work on interesting projects together, which would otherwise be simply not possible.