Cmake-language-server - CMake LSP Implementation

Overview

cmake-language-server

PyPI AUR version GitHub Actions (Tests) codecov GitHub

CMake LSP Implementation.

Alpha Stage, work in progress.

Features

  • Builtin command completion
  • Documentation for commands and variables on hover
  • Formatting

Commands

  • cmake-language-server: LSP server
  • cmake-format: CLI frontend for formatting

Installation

$ pip install cmake-language-server

Tested Clients

Neovim

coc.nvim
  "languageserver": {
    "cmake": {
      "command": "cmake-language-server",
      "filetypes": ["cmake"],
      "rootPatterns": [
        "build/"
      ],
      "initializationOptions": {
        "buildDirectory": "build"
      }
    }
  }
vim-lsp
if executable('cmake-language-server')
  au User lsp_setup call lsp#register_server({
  \ 'name': 'cmake',
  \ 'cmd': {server_info->['cmake-language-server']},
  \ 'root_uri': {server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'build/'))},
  \ 'whitelist': ['cmake'],
  \ 'initialization_options': {
  \   'buildDirectory': 'build',
  \ }
  \})
endif

Configuration

  • buildDirectory This language server uses CMake's file API to get cached variables. The API communicates using <buildDirectory>/.cmake/api/. buildDirectory is relative path to the root uri of the workspace. To configure the build tree, you need to run the cmake command such as cmake .. -DFOO=bar.
Comments
  • Basic AST parsing and some starter diagnostics

    Basic AST parsing and some starter diagnostics

    This is kind of a big PR, but I hope you'll find it worth your while.

    This introduces basic AST parsing on the basis of the grammar you wrote. I made a duplicate grammar that

    • suppresses all the whitespace and comments
    • distinguish control flow (conditionals, loops, function/macro declarations) from regular command invocations
    • adds block-level expectation parsing (opening a function implies there must be an endfunction somewhere)
    • adds semantic actions to generate AST nodes

    The cool thing about the expectation parsing (using the - instead of +) is that it can get you get an exception if you forget to close a block, which can be easily converted into a diagnostic!

    Adds TEXT_DOCUMENT_DID_OPEN/_SAVE features to the language server, which parses the file into an AST and generates diagnostics for single list file only. If the AST parsing was successful, it gets traversed by a bunch of diagnostic-generating visitors much in the style of python's AST module (i.e. if the visitor has a visit_<ASTNode-type-name> method matching the type of the node being visited, that function gets called).

    I've only added the following diagnostics, whose logic may or may not be flawed at this point:

    • break() or continue() not enclosed in a loop
    • return() in a macro (suggest replacement with message(FATAL_ERROR ...))
    • redundant assignment: set(asdf ${asdf}) (Yeah, I got bit by this recently :grimacing:)
    • duplicate branch in if/elseif
    • all-uppercase commands (suggest lowercase)
    • directory-based api (suggest replacement with target-based api)

    Naturally, these are all up for discussion or omission. They're kind of a starter list, since I bet there's a bunch more helpful diagnostics that could be implemented. But maybe we should decide on the general structure for them first, hence this PR.

    I also messed around a little in the rest of the files. Fixed a few misspellings and added documentation in some places when I was first trying to find my way around the code.

    opened by jargonzombies 6
  • poetry: update pygls to version 0.11.2

    poetry: update pygls to version 0.11.2

    Update pygls to version 0.11.2 and change the version requirement to '^0.11' this removes a conflict with jedi-language-server which requires pygls>=0.11.1,<0.12.0.

    This commit also bumps the cmake-language-server version to 0.1.3.

    opened by charlievieth 5
  • poetry: update pygls to version 0.12

    poetry: update pygls to version 0.12

    Update pygls to version 0.12 to remove a conflict with jedi-language-server which requires pygls "^0.12" and set the minimum python version to py37 (as required by pygls 0.12).

    This commit also bumps the cmake-language-server version to 0.1.36

    opened by charlievieth 3
  • Thoughts on the formatter

    Thoughts on the formatter

    I just noticed that there doesn't seem to be much/any documentation on the formatter's options/args, and was wondering if it's configurable, and/or what the defaults even are?

    As an aside, do you have any thoughts on splitting the formatter into its own package? I'm just saying this because I noticed that this LSP actually conflicts (same binary name cmake-format) with https://github.com/cheshirekow/cmake_format which seems to possibly be a more fleshed out formatter.

    opened by sum01 3
  • Exception when requesting textDocument/hover

    Exception when requesting textDocument/hover

    Given the following cmake file: https://github.com/llvm/llvm-project/blob/master/libc/src/stdio/CMakeLists.txt

    If I hover over add_entrypoint_object, I see the following exception:

    cmake: ERROR:pygls.protocol:Failed to handle request 2 textDocument/hover Object(position=Object(character=7, line=0), textDocument=Object(uri='file:///home/raoul/Documents/Programming/llvm-project/libc/src/stdio/CMakeLists.txt'))
    :: --> cmake textDocument/hover(2): {'position': {'character': 7, 'line': 0}, 'textDocument': {'uri': 'file:///home/raoul/Documents/Programming/llvm-project/libc/src/stdio/CMakeLists.txt'}}
    cmake: Traceback (most recent call last):
    :: <~~ cmake 2: {'message': "AttributeError: 'NoneType' object has no attribute 'get_command_doc'", 'code': -32602, 'data': '{\'traceback\': [\'  File "/home/raoul/.config/sublime-text-3/Cache/LSP-cmake/lib/python3.8/site-packages/pygls/protocol.py", line 317, in _handle_request\\n    self._execute_request(msg_id, handler, params)\\n\', \'  File "/home/raoul/.config/sublime-text-3/Cache/LSP-cmake/lib/python3.8/site-packages/pygls/protocol.py", line 242, in _execute_request\\n    self._send_response(msg_id, handler(params))\\n\', \'  File "/home/raoul/.config/sublime-text-3/Cache/LSP-cmake/lib/python3.8/site-packages/cmake_language_server/server.py", line 142, in hover\\n    doc = c(word[0])\\n\', \'  File "/home/raoul/.config/sublime-text-3/Cache/LSP-cmake/lib/python3.8/site-packages/cmake_language_server/server.py", line 136, in <lambda>\\n    lambda x: self._api.get_command_doc(x.lower()),\\n\']}'}
    cmake:   File "/home/raoul/.config/sublime-text-3/Cache/LSP-cmake/lib/python3.8/site-packages/pygls/protocol.py", line 317, in _handle_request
    cmake:     self._execute_request(msg_id, handler, params)
    cmake:   File "/home/raoul/.config/sublime-text-3/Cache/LSP-cmake/lib/python3.8/site-packages/pygls/protocol.py", line 242, in _execute_request
    cmake:     self._send_response(msg_id, handler(params))
    cmake:   File "/home/raoul/.config/sublime-text-3/Cache/LSP-cmake/lib/python3.8/site-packages/cmake_language_server/server.py", line 142, in hover
    cmake:     doc = c(word[0])
    cmake:   File "/home/raoul/.config/sublime-text-3/Cache/LSP-cmake/lib/python3.8/site-packages/cmake_language_server/server.py", line 136, in <lambda>
    cmake:     lambda x: self._api.get_command_doc(x.lower()),
    cmake: AttributeError: 'NoneType' object has no attribute 'get_command_doc'
    

    Editor: Sublime Text with LSP plugin cmake-language-server version: 0.1.2

    opened by rwols 3
  • cmake-format from standard input

    cmake-format from standard input

    Can cmake-format have support for formatting a file from standard input to standard output? Something like cmake-format --stdin. This would be useful for editor plugins.

    opened by lassik 3
  • Fixed build system requirements in pyproject.toml.

    Fixed build system requirements in pyproject.toml.

    Poetry depends on lot of dependencies having nothing common with building packages. That's why poetry-core was created, which has much less dependencies and more focused on building wheels.

    opened by KOLANICH 2
  • Install error

    Install error

    Not sure how to proceed.

    ERROR: Could not find a version that satisfies the requirement cmake-language-server (from versions: none)
    ERROR: No matching distribution found for cmake-language-server
    
    opened by loshjawrence 2
  • insertText property provided with null

    insertText property provided with null

    Several LSP plugins, such as nvim-native, vim-lamp (already fixed in https://github.com/hrsh7th/vim-lamp/issues/21) and vim-lsp have no completion with it. Author of vim-lamp said that cmake-language-server provided insertText with null. Could you fix it?

    opened by Shatur 2
  • Missing target_precompile_headers

    Missing target_precompile_headers

    target_precompile_headers


    As a side note, do you have any desire to support included packages (that are distributed) that bring in their own vars/functions? Things like FindPackageHandleStandardArgs, FindPackageMessage, or cmake_dependent_option as an example.

    opened by sum01 2
  • The `textDocument/completion` request may not contains the `request` parameter

    The `textDocument/completion` request may not contains the `request` parameter

    Hello,

    Thank you for this server,

    I have a problem using this LSP server, concerning the textDocument/completion request. It seems the server expect a context parameter while the LSP specification if I am not mistaken has it as optional: From the microsoft website

    Request:
    
    method: ‘textDocument/completion’
    
    params: CompletionParams defined as follows:
    
    export interface CompletionParams extends TextDocumentPositionParams, WorkDoneProgressParams, PartialResultParams {
    	/**
    	 * The completion context. This is only available if the client specifies
    	 * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
    	 */
    	context?: CompletionContext;
    }
    

    For context, I am trying to make this LSP server works with the kakoune lsp plugin see related issue here.

    opened by CharlesGueunet 2
  • Differences in document hover content

    Differences in document hover content

    Hello, I'm switch from coc.nvim to neovim builtin Lsp, but I noticed the document hover content is entirely different. Document hover from coc.nvim is as follow: image However, when I toggle document hover for the same command (add_executable), I only got:

    add_executable(<name> [WIN32] [MACOSX_BUNDLE]
                   [EXCLUDE_FROM_ALL]
                   [source1] [source2 ...])
    
    

    In addition, when I toggle document hover for for example find_package, I only got find_package() and nothing else.

    I'd like to know what the original behavior should be, and whether the detailed documentation is generated by coc-cmake, or whether I'm not getting the same results on nvim-lsp because of the configuration.

    opened by YuCao16 0
  • format

    format

    I install cmake-format and config cmake-language-server

      "languageserver": {
        "cmake": {
          "command": "cmake-language-server",
          "filetypes": ["cmake"],
          "rootPatterns": [
            "build/"
          ],
          "initializationOptions": {
            "buildDirectory": "build"
          }
        }
      }
    

    It can't format CMakeLists.txt when I saved it.

    opened by kdurant 1
  • Detect Definitions in {project_root}/cmake/XYZ.cmake

    Detect Definitions in {project_root}/cmake/XYZ.cmake

    I am using the coc.nvim client and I have a CMakeLists.txt which includes a helper.cmake (e.g. include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeHelper.cmake)) file to define macros. I would like to be able to jump to the definition of these macros. I know that this is possible with ctags. Is there a way to use the language-server to jump to such a macro definition instead?

    opened by 3ddiddE 2
  • Windows new-line breaks parser

    Windows new-line breaks parser

    On windows I couldn't get a CMakeLists.txt to parse. I tried adding a test like this:

    test_windows_newline = make_parser_test("a()\r\n", [("a", []), '\r', '\n'])

    But it doesn't pass and returns no tokens.

        def test() -> None:
            actual_token, actual_remain = ListParser().parse(liststr)
    >       assert actual_token == expect_token
    E       AssertionError: assert [] == [('a', []), '\r', '\n']
    E         Right contains 3 more items, first extra item: ('a', [])
    E         Full diff:
    E         - [('a', []), '\r', '\n']
    E         + []
    
    opened by Lorac 0
  • E5108: Error executing lua ...neovim/HEAD-f2906a4_2/share/nvim/runtime/lua/vim/lsp.lua:1317: table index is nil

    E5108: Error executing lua ...neovim/HEAD-f2906a4_2/share/nvim/runtime/lua/vim/lsp.lua:1317: table index is nil

    ❯ pip3 list | grep cmake-language-server
    cmake-language-server  0.1.2
    ❯ pip3 --version
    pip 21.1.2 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
    ❯ nvim --version
    NVIM v0.5.0-dev+1384-gf2906a466
    Build type: Release
    LuaJIT 2.1.0-beta3
    Compilation: clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20210607-31073-mvxyy9/build/config -I/tmp/neovim-20210607-31073-mvxyy9/src -I/usr/local/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/usr/local/opt/gettext/include -I/tmp/neovim-20210607-31073-mvxyy9/build/src/nvim/auto -I/tmp/neovim-20210607-31073-mvxyy9/build/include
    Compiled by [email protected]
    
    Features: +acl +iconv +tui
    See ":help feature-compile"
    
       system vimrc file: "$VIM/sysinit.vim"
      fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD-f2906a4_2/share/nvim"
    
    Run :checkhealth for more info
    

    When I open a CMakeLists.txt, I got errors:

    Error detected while processing CursorHold Autocommands for "*":
    E5108: Error executing lua ...neovim/HEAD-f2906a4_2/share/nvim/runtime/lua/vim/lsp.lua:1317: table index is nil
    
    opened by hungrybirder 0
Owner
Regen
Regen
A language server protocol implementation

A barebone LSP implementation Starting point for server implementations of the LSP protocol. Provides the infrastructure to easily hook in functionali

Henner Zeller 4 Jan 18, 2022
Windows named pipe server that forwards connections to given TCP server

PipeTcp An asynchronous Windows named pipe server that forwards connections to given TCP server. Pre-built binaries can be found in Releases. Invocati

Jinoh Kang 4 May 23, 2022
A project designed for the esp8266 D1 Mini or the esp8266 D1 Mini PRO to provide a wifi http server and dns server.

PS4 Server 9.00 This is a project designed for the esp8266 D1 Mini or the esp8266 D1 Mini PRO to provide a wifi http server and dns server. this is fo

null 13 Sep 7, 2022
WAFer is a C language-based software platform for scalable server-side and networking applications. Think node.js for C programmers.

WAFer WAFer is a C language-based ultra-light scalable server-side web applications framework. Think node.js for C programmers. Because it's written i

Riolet Corporation 693 Aug 16, 2022
Unofficial language server for Luau.

Luau language server Disclaimer: this project is unofficial! Extensions powered by lls vscode-lls (in development) Architecture Because Lua and by ext

Alexander McCord 4 May 12, 2022
An Ace of Spades server implementation done in C

SpadesX What is SpadesX and why ? TL;DR Ace of Spades server written in C (Currently in full on development and thus early Alpha) Now if you would lik

null 32 Sep 25, 2022
A Tcp/Ip stack implementation on top of Solarflare ef_vi, and a C++ headers only framework for tcp multiplexing client/server.

Efvitcp Efvitcp is a tcp library using Solarflare ef_vi interface on linux, and also a tcp multiplexing framework for both C++ client and server progr

Meng Rao 22 Sep 27, 2022
mvfst is a client and server implementation of IETF QUIC protocol in C++ by Facebook.

mvfst (Pronounced move fast) is a client and server implementation of IETF QUIC protocol in C++ by Facebook.

Meta Incubator 1.2k Oct 3, 2022
an easy implementation of a multi-process tcp server and a multi-thread tcp client

一个TCP多进程服务器-多线程客户端的简单实现。 客户端类似Apache ab的测试功能,能够通过向某一个ip端口发送指定并发量和总数量的tcp短连接;服务端处理tcp短连接,每来一条消息就打印一条log。 使用cmake编译,建议在vscode里编译,或者命令行 # 终端进入目录 mkdir bu

adin 1 Nov 28, 2021
Apache Thrift is a lightweight, language-independent software stack for point-to-point RPC implementation

Apache Thrift Introduction Thrift is a lightweight, language-independent software stack for point-to-point RPC implementation. Thrift provides clean a

The Apache Software Foundation 9.4k Sep 27, 2022
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.

Welcome! The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design

Microsoft 7.1k Oct 5, 2022
Cross-platform, efficient, customizable, and robust asynchronous HTTP/WebSocket server C++14 library with the right balance between performance and ease of use

What Is RESTinio? RESTinio is a header-only C++14 library that gives you an embedded HTTP/Websocket server. It is based on standalone version of ASIO

Stiffstream 886 Sep 24, 2022
A C++ header-only HTTP/HTTPS server and client library

cpp-httplib A C++11 single-file header-only cross platform HTTP/HTTPS library. It's extremely easy to setup. Just include the httplib.h file in your c

null 7.8k Sep 26, 2022
Ultra fast and low latency asynchronous socket server & client C++ library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution

CppServer Ultra fast and low latency asynchronous socket server & client C++ library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and

Ivan Shynkarenka 891 Sep 28, 2022
H2O - the optimized HTTP/1, HTTP/2, HTTP/3 server

H2O - an optimized HTTP server with support for HTTP/1.x, HTTP/2 and HTTP/3 (experimental) Copyright (c) 2014-2019 DeNA Co., Ltd., Kazuho Oku, Tatsuhi

H2O 10.1k Oct 3, 2022
C++ library for creating an embedded Rest HTTP server (and more)

The libhttpserver reference manual Tl;dr libhttpserver is a C++ library for building high performance RESTful web servers. libhttpserver is built upon

Sebastiano Merlino 686 Sep 27, 2022
Mongoose Embedded Web Server Library - a multi-protocol embedded networking library with TCP/UDP, HTTP, WebSocket, MQTT built-in protocols, async DNS resolver, and non-blocking API.

Mongoose - Embedded Web Server / Embedded Networking Library Mongoose is a networking library for C/C++. It implements event-driven non-blocking APIs

Cesanta Software 8.8k Sep 28, 2022
Event-driven network library for multi-threaded Linux server in C++11

Muduo is a multithreaded C++ network library based on the reactor pattern. http://github.com/chenshuo/muduo Copyright (c) 2010, Shuo Chen. All righ

Shuo Chen 12k Sep 26, 2022
A collection of C++ HTTP libraries including an easy to use HTTP server.

Proxygen: Facebook's C++ HTTP Libraries This project comprises the core C++ HTTP abstractions used at Facebook. Internally, it is used as the basis fo

Facebook 7.6k Oct 2, 2022