Coder Social home page Coder Social logo

cdt-lsp's Introduction

Eclipse CDT LSP - LSP based C/C++ Editor

Target audience are Eclipse plugin developers who want to use/develop a LSP based C/C++ Editor.

This plugin is based on the LSP4E and TM4E Eclipse projects. The editor is based on the ExtensionBasedTextEditor in Eclipse.

The org.eclipse.cdt.lsp is the core plugin. C/C++ IDE Developers can use the serverProvider extension point to define a C/C++ language server. If there is no extension defined, the LLVM clangd language server will be used and searched on the PATH environment variable. Clangd searches for a compile_commands.json file in the source file folder and its parents. It's needed to determine the compile informations. In the default clangd configuration, the PATH will be searched for a gcc compiler to determine the default compiler include paths.

The editor is basically the ExtensionBasedTextEditor. The language grammar comes from TM4E.

screenshot.png

The Editors features depends on the support on client (LSP4E) and server (clangd) side. Currently these feature are supported (clangd 15.0.3) and current LSP4E:

  • Auto completion
  • Hovering
  • Formatting
  • Go to Declaration
  • Find References
  • Code actions (Declare implicit copy/move members, Extract to function/variable, rename)
  • Quick Fix (Ctrl+1)
  • Type hierarchy (quick hierarchy view only)
  • Call hierarchy
  • Outline view

Not supported (yet):

  • Include browser (Eclipse CDT speciality)

Activating LSP based C/C++ Editor

The org.eclipse.cdt.lsp.clangd plugin provides an activation UI for the LSP based C/C++ Editor on project and workspace level. The clangd language server path and the arguments can be changed in the workspace preferences as well:

image

Newly created C/C++ projects will use the settings from the workspace preferences. This can be changed in the project properties:

image

Different C/C++ projects using the old and new C/C++ editor can be mixed in one workspace. The linked include files will be opened with the same editor.

To use these plugins import them in your CDT sources.

TODO: see issues

Try it out

  1. Download the latest Developer Build of Eclipse for C/C++ Developers or Eclipse for Embedded C/C++ Developers using the Eclipse installer or downloading and extracting the latest milestone available on eclipse.org.
  2. Add https://download.eclipse.org/tools/cdt/builds/cdt-lsp/master/ to your Available Software Sites and install C/C++ LSP Support in the Eclipse CDT LSP Category and restart Eclipse.
  3. Install Pre-requisites listed below
  4. Create a CMake project or import an existing project following guidelines below
  5. Enable the LSP based C/C++ Editor following instructions above.

See contribution guide for details on running CDT LSP from source.

Install pre-requisites

The following tools are needed on the PATH to operate the demo.

Import an existing project

You can import an existing project that contains a compile_commands.json file, or follow these instructions to create a simple starting project.

Create an example CMake project

  1. File -> New -> Project...
  2. Choose C/C++ -> C/C++ Project and press Next
  3. Choose CMake Project and press Next
  4. Enter a name for the project, e.g. example (avoid special characters and dashes, see eclipse-cdt/cdt#288)
  5. Press Finish
  6. Build the project to create the Compilation Database (compile_commands.json file)

The root of the project contains a .clangd file which tells clangd where clangd should fine the compilation database. This file may be hidden by default, therefore to see the file uncheck the .* resources in the filters for the Project Explorer view

Open a file

By default C/C++ will be opened with the standard CEditor. The default can be changed per project or per workspace with the C/C++ General -> Editor (LSP) -> Prefer C/C++ Editor (LSP) checkbox in the project setting or preferences.

  • Note: The workspace setting will be used for new projects only. To use the LSP based editor on a project, Prefer C/C++ Editor (LSP) must be activated in the project properties.

Alternatively, you can choose which editor to open the file by using Open With:

open-with.png

With the C/C++ Editor (LSP) open, the presentation of the C++ file will follow the LSP4E conventions augmented by the information returned from clangd.

hello-world.png

Known issues

See the open issues for known issues and workarounds while the code is in active development.

cdt-lsp's People

Contributors

ghentschke avatar jonahgraham avatar ddscharfe avatar ruspl-afed avatar kolipakakondal avatar chrismathis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.