Language servers

Francisco Lopes edited this page Dec 20, 2018 · 50 revisions

Contents

Supported features

Check out the official specification at https://microsoft.github.io/language-server-protocol/specification.

  • General

    • initialize
    • initalized
    • shutdown
    • exit
    • $/cancelRequest
  • Window

    • showMessage
    • showMessageRequest
    • logMessage
  • Telemetry

    • event (just log the event)
  • Client

    • registerCapability
    • unregisterCapability
  • Workspace

    • workspaceFolders
    • didChangeWorkspaceFolders
    • didChangeConfiguration
    • configuration
    • didChangeWatchedFiles
    • symbol
    • executeCommand
    • applyEdit
    • resource operations
  • Text Synchronization

    • didOpen
    • didChange
    • willSave
    • willSaveWaitUntil
    • didSave
    • didClose
  • Diagnostics

    • publishDiagnostics
  • Language Features

    • completion
    • completion resolve
    • hover
    • signatureHelp
    • definition
    • typeDefinition
    • implementation
    • references
    • documentHighlight
    • documentSymbol
    • codeAction
    • codeLens
    • codeLens resolve
    • documentLink
    • documentLink resolve
    • documentColor
    • colorPresentation
    • formatting
    • rangeFormatting
    • onTypeFormatting
    • prepare rename
    • rename
    • foldingRange

Note: different server could have different capabilities.

Register custom language servers

User defined language servers are configured in languageserver field of configuration file.

There're three types of language servers: module,executable and socket.

  • module type language server are running by nodejs and using node IPC for connection.
  • executable type language server are spawned with executable command while using stdio for connection.
  • socket language server are started in separated process, normally used for debugging purpose.

Different language server type have different configuration schema.

An example of module language server:

  "languageserver": {
    "foo": {
      "module": "/usr/local/lib/node_modules/foo/index.js",
      "args": ["--node-ipc"],
      "filetypes": ["foo"],
      "trace.server": "verbose",
      "rootPatterns": ["root.yml"],
      // Used for debugging
      "execArgv": ["--nolazy", "--inspect-brk=6045"],
      "initializationOptions": {
      },
      "settings": {
        "validate": true
      }
    }
  }

module and filetypes are required for module language server.

An example of executable language server:

  "languageserver": {
    "bar": {
      "command": "bar",
      "args": ["--stdio"],
      "filetypes": ["bar"],
      "cwd": "./src",
      "initializationOptions": {
      },
      "settings": {
      }
    }
  }

command and filetypes are required for executable language server.

An example of socket language server:

"languageserver": {
    "socketserver": {
      "host": "127.0.0.1",
      "port": 9527
    }
  }

port is required for socket service and user should start the socket server before coc started.

  • initializationOptions is the json object that passed to language server on initialize.
  • settings contains specific configuration of language server.
  • trace.server controls trace level of communication between server and client, default "off", change to "verbose" if you want to checkout all communication.
  • rootPatterns is used for resolve root path which should contain one of patterns as child directory or file, it will use g:rooter_patterns (default to ['.vim/', '.git/', '.hg/', '.projections.json']) when not specified,

Example configuration for custom language servers

Add languageserver section in your coc-settings.json for regist custom language servers.

Dart

Using natebosch/dart_language_server:

  "languageserver": {
    "dart": {
      "command": "dart_language_server",
      "args": [],
      "filetypes": ["dart"],
      "initializationOptions": {},
      "settings": {
        "dart": {
          "validation": {},
          "completion": {}
        }
      }
    }
  }

C/C++/Objective-C

Using ccls

  "ccls": {
    "command": "ccls",
    "filetypes": ["c", "cpp", "objc", "objcpp"],
    "rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
    "initializationOptions": {
      "cacheDirectory": "/tmp/ccls"
    }
  }

Using cquery

  "languageserver": {
    "cquery": {
      "command": "cquery",
      "args": ["--log-file=/tmp/cq.log"],
      "filetypes": ["c", "cpp"],
      "rootPatterns": ["compile_flags.txt", "compile_commands.json", ".vim/", ".git/", ".hg/"],
      "initializationOptions": {
        "cacheDirectory": "/tmp/cquery"
      }
    }
  }

Using clangd

  "languageserver": {
    "clangd": {
      "command": "clangd",
      "rootPatterns": ["compile_flags.txt", "compile_commands.json", ".vim/", ".git/", ".hg/"],
      "filetypes": ["c", "cpp", "objc", "objcpp"]
    }
  }

Like many tools, clangd relies on the presence of a JSON compilation database

Go

Using saibing/bingo

  "languageserver": {
    "golang": {
      "command": "bingo",
      "rootPatterns": ["go.mod", ".vim/", ".git/", ".hg/"],
      "filetypes": ["go"]
    }
  }

Using sourcegraph/go-langserver

  "languageserver": {
    "golang": {
      "command": "go-langserver",
      "filetypes": ["go"],
      "initializationOptions": {
        "gocodeCompletionEnabled": true,
        "diagnosticsEnabled": true,
        "lintTool": "golint"
      }
    }
  }

PHP

Using felixfbecker/php-language-server

  "languageserver": {
    "phplang": {
      "command": "php",
      "args": ["vendor/felixfbecker/language-server/bin/php-language-server.php"],
      "filetypes": ["php"]
    }
  }

Dockerfile

Using rcjsuen/dockerfile-language-server-nodejs

  "languageserver": {
    "dockerfile": {
      "command": "docker-langserver",
      "filetypes": ["dockerfile"],
      "args": ["--stdio"]
    }
  }

Bash

Using mads-hartmann/bash-language-server

  "languageserver": {
    "bash": {
      "command": "bash-language-server",
      "args": ["start"],
      "filetypes": ["sh"],
      "ignoredRootPaths": ["~"]
    }
  }

Lua

Using Alloyed/lua-lsp

  "languageserver": {
    "lua": {
      "command": "lua-lsp",
      "filetypes": ["lua"]
    }
  }

OCaml and ReasonML

Using ocaml-language-server

  "languageserver": {
     "ocaml": {
       "command": "ocaml-language-server",
       "args": ["--stdio"],
       "filetypes": ["ocaml", "reason"]
     }
  }

Using reason-language-server

  "languageserver": {
     "reason": {
      "command": "/absolute/path/to/reason-language-server.exe",
      "filetypes": ["reason"]
     }
  }

Flow

Using flow-language-server

  // disable tsserver for javascript
  "tsserver.enableJavascript": true,
  "languageserver": {
    "flow": {
      "command": "flow-language-server",
      "args": ["--stdio"],
      "filetypes": ["javascript", "javascriptreact"],
      "rootPatterns": [".flowconfig"]
    },
  }
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.