sylvestre.ledru created this revision.
sylvestre.ledru added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous,
MaskRay, ilya-biryukov.
Herald added a project: clang.
sylvestre.ledru updated this revision to Diff 249595.
sylvestre.ledru added a comment.
Add a link to the doc
clangd is designed for IDE usage but having a simple test case
explains how it works.
It will help newcomers or potential users.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D75985
Files:
clang-tools-extra/docs/clangd/SimpleExample.rst
clang-tools-extra/docs/clangd/index.rst
Index: clang-tools-extra/docs/clangd/index.rst
===================================================================
--- clang-tools-extra/docs/clangd/index.rst
+++ clang-tools-extra/docs/clangd/index.rst
@@ -8,6 +8,7 @@
Installation
Features
Configuration
+ SimpleExample
What is clangd?
===============
Index: clang-tools-extra/docs/clangd/SimpleExample.rst
===================================================================
--- /dev/null
+++ clang-tools-extra/docs/clangd/SimpleExample.rst
@@ -0,0 +1,109 @@
+=====================
+Simple example clangd
+=====================
+
+clangd is not designed to be used in command line.
+However, we are providing this example to show how it works.
+
+The following file (ex: commands.json) represent a list of commands.
+
+.. code-block:: json
+
+ {
+ "jsonrpc": "2.0",
+ "id": 0,
+ "method": "initialize",
+ "params": {
+ "capabilities": {
+ "textDocument": {
+ "completion": {
+ "completionItem": {
+ "snippetSupport": true
+ }
+ }
+ }
+ },
+ "trace": "off"
+ }
+ }
+ ---
+ {
+ "jsonrpc": "2.0",
+ "method": "textDocument/didOpen",
+ "params": {
+ "textDocument": {
+ "uri": "test:///main.cpp",
+ "languageId": "cpp",
+ "version": 1,
+ "text": "int func_with_args(int a, int b);\nint main() {\nfunc_with\n}"
+ }
+ }
+ }
+ ---
+ {
+ "jsonrpc": "2.0",
+ "id": 1,
+ "method": "textDocument/completion",
+ "params": {
+ "textDocument": {
+ "uri": "test:///main.cpp"
+ },
+ "position": {
+ "line": 2,
+ "character": 7
+ }
+ }
+ }
+ ---
+ {
+ "jsonrpc": "2.0",
+ "id": 4,
+ "method": "shutdown"
+ }
+ ---
+ {
+ "jsonrpc": "2.0",
+ "method": "exit"
+ }
+
+
+To run all the commands at once:
+
+.. code-block:: shell
+
+ clangd -lit-test < commands.json
+
+This example will try to get the completion on line 2, column 7.
+Here is a subset of the returned information:
+
+.. code-block:: json
+
+ [...]
+ "items": [
+ {
+ "detail": "int",
+ "filterText": "func_with_args",
+ "insertText": "func_with_args(${1:int a}, ${2:int b})",
+ "insertTextFormat": 2,
+ "kind": 3,
+ "label": " func_with_args(int a, int b)",
+ "score": 9.9000005722045898,
+ "sortText": "3ee19999func_with_args",
+ "textEdit": {
+ "newText": "func_with_args(${1:int a}, ${2:int b})",
+ "range": {
+ "end": {
+ "character": 7,
+ "line": 2
+ },
+ "start": {
+ "character": 0,
+ "line": 2
+ }
+ }
+ }
+ }
+ [...]
+
+`newText` shows that clangd is able to find a suggestion for the completion and
+where to insert it.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits