Skip to content

Instantly share code, notes, and snippets.

@ManishKhurana11
Last active October 15, 2019 06:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ManishKhurana11/f940b82c8cebe04ee1bb91ebb2ac861d to your computer and use it in GitHub Desktop.
Save ManishKhurana11/f940b82c8cebe04ee1bb91ebb2ac861d to your computer and use it in GitHub Desktop.
GSoC 2018 - Eclipse CDT: Integration with the Language Server Protocol

GSoC 2018 - Eclipse CDT: Integration with the Language Server Protocol

Overview and Introduction

About Language Server Protocol

The Language Server Protocol (LSP) is an open, JSON-RPC-based protocol for use between source code editors or integrated development environments (IDEs) and servers that provide programming language-specific features. The goal of the protocol is to allow programming language support to be implemented and distributed independently of any given editor or IDE. This way, a single Language Server can be re-used in multiple development tools, which in turn can support multiple languages with minimal effort.

A Language Server is meant to provide the language-specific smarts and communicate with development tools over a protocol that enables inter-process communication.

More information about LSP can be found on Official Page for Language Server Protocol and its Wikipedia page

About Eclipse CDT

The Eclipse C++ Development Tooling (CDT) is a fully functional C and C++ Integrated Development Environment based on the Eclipse platform. Features include: support for project creation and managed build for various toolchains, standard make build, source navigation, various source knowledge tools, such as type hierarchy, call graph, include browser, macro definition browser, code editor with syntax highlighting, folding and hyperlink navigation, source code refactoring and code generation, visual debugging tools, including memory, registers, and disassembly viewers.

More information can be found here

About GSoC Project

Eclipse CDT (C/C++ Development Tools) currently uses a homegrown C++ parser and code analysis engine for providing semantics-aware navigation, completion, refactoring, and other editing features. This parser has fallen behind in C++ language support (e.g. it currently has only partial C++14 support and no C++17 support) and is increasingly a maintenance burden.

The Language Server Protocol is a protocol that allows decoupling "language servers" that provide support for semantics-aware features, from editors / IDEs that provide the UI for these features. This facilitates reusing the parser and code analysis engine already present in a compiler like clang, exposed via a language server. There is a project underway to support the client side of the protocol in Eclipse, LSP4E.

The goal of this project was to integrate Eclipse CDT with clang-based C/C++ language servers :-

More information can be found here

Work that was to be done

  • Enhancements to LSP4E (support for new parts of the protocol, or enhancements to the implementation of existing parts), as motivated by CDT's needs.

  • Enhancements to CDT to make using the LSP integration smoother (e.g. project configuration, making use of existing settings)

  • Enhancements to CDT to implement LSP protocol extensions that are specific to C/C++, or to a particular C/C++ language server (for example, cquery supports a protocol extension for semantic highlighting that might be neat to support in CDT)

More information can be found here

Links for the work done

Eclipse CDT repository : https://git.eclipse.org/c/cdt/org.eclipse.cdt.git/log/

My commits that are merged into Eclipse CDT Repository : https://git.eclipse.org/c/cdt/org.eclipse.cdt.git/log/?qt=grep&q=manish

Work I did and Demo

These were the features along with their bug reports which were implemented:

Commit Details
Bug 534669. Added Preference Page for LSP4E-CPP LSP4E-CPP Preference Page This adds a preference page for LSP4E-CPP plugin. In it user can select the desired Language Server (CQuery or ClandD). The path to the language sever is automatically found if it is in system PATH or user could browse the path manually. User can also specify any command-line argument for the Language Server in the preference page
Bug 535632. Set a cache directory for CQuery LS This sets the default cache directory for the indexing of files by CQuery Language Server
Bug 535629. Add empty implementation for unsupported CQuery notifications This adds empty implementation for CQuery specific Server --> Client messages. These messages are : "$cquery/progress" , "$cquery/setInactiveRegions" and "$cquery/publishSemanticHighlights"
Bug 535631. Cquery is now able to find compile_commands.json Cquery can now find compile_commands.json in project folder. The compile_commands.json files are a mechanism for clang-based tools (including language servers) to know what compiler commands are used to compile files in a codebase. It's a simple json format with keys being file paths, and values being compiler command strings.
Bug 536381. Add propertyChange() method to Preference Page Path property change in preference page Now on changing Language Server in LSP4E Preference Page, the path to Language Server also changes automatically if LS is in system PATH
Bug 536797. Add implement for "$cquery/progress" notification message from cquery Cquery progress in bottom status bar Implementation for "$cquery/progress" message added. It shows if the CQuery LS is 'Idle' or 'Busy' in bottom status bar of Eclipse.
Bug 537030. Add implementation for "$cquery/setInactiveRegions" notification message Inactive code highlighting in LSP4E-CPP Implementation for "$cquery/setInactiveRegions" added. Now the Inactive Code gets highlighted in Eclipse.
Bug 537385. Add initialization options for inactive regions and semantic highlights Options to enable/disable Inactive Code Highlighting and Semantic Highlighting added. User can now opt if to display these or not from the existing settings for these in Eclipse.
Bug 537306 - Add implementation for "$cquery/publishSemanticHighlights" Semantic Highlighting in LSP4E-CPP Implementation for "$cquery/publishSemanticHighlights" added. Now there is both Lexical Highlighting (from Eclipse) and Semantic Highlighting (from Cquery) in C++ source files. Semantic Highlighting circled in yellow in Demo picture
Bug 535428. Add indentation and bracket completion support in LSP4E-CPP Auto-indentation and bracket completion in LSP4E-CPP Auto-indentation and bracket completion support added to LSP4E-CPP's Generic Editor
Bug 537102. Add use of position object for inactive code and semantic highlighting Using Position Object installed on document for semantic and inactive code highlighting Highlighted position objects are added to the document object so that position updater could update the positions if there is any change in it

Challenges and Learning

As Language Server Protocol is a new feature for Text Editors and IDEs, there is not much helping content available on the internet. Also I wasn't able to fully understand Eclipse libraries on my own but my mentor Mr. Nathan Ridge fully helped me in all the difficulties I faced in this project. I read some of the CQuery's code to implement it's messages and protocol extension in Eclipse. We also contacted the cquery-developers during the project to ask some queries and to provide some feedback about cquery to them.

But, overall this was a great learning and fun experience. I learned several new things in Java and my programming skills have also improved. I got the idea about how professional softwares are written and also that how people contribute to Open Source inspite of their day-job.

Future Developments

Features that would be added into LSP4E-CPP in future :

Acknowledgement and Conclusion

All this work which I have done in this project was possible because of the help provided by my mentor, Mr. Nathan Ridge. Anytime I was stuck on a problem and couldn't figure out a solution, he was always there to help me. He beautifully structured the tasks for this 3 months-GSoC journey.

Also, I wanted to thank Google for organising Google Summer of Code programme and giving me opportunity to work with such a big Open Source Oragnization and such an experienced mentor. This program helps many students (such as me) to begin their journey of Open Source and also strengthen the Open Source Community.

GSoC was a great experience and it has motivated me even more to participate and contribute in Open Source.

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