summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/ClangdLSPServer.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [clangd] New conventions for JSON-marshalling functions, centralize machinerySam McCall2017-11-301-2/+2
| | | | | | | | | | | | | | | | | | Summary: - JSON<->Obj interface is now ADL functions, so they play nicely with enums - recursive vector/map parsing and ObjectMapper moved to JSONExpr and tested - renamed (un)parse to (de)serialize, since text -> JSON is called parse - Protocol.cpp gets a bit shorter Sorry for the giant patch, it's prety mechanical though Reviewers: ilya-biryukov Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D40596 llvm-svn: 319478
* [clangd] Switch from YAMLParser to JSONExprSam McCall2017-11-281-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: - Converted Protocol.h parse() functions to take JSON::Expr. These no longer detect and log unknown fields, as this is not that useful and no longer free. I haven't changed the error handling too much: fields that were treated as optional before are still optional, even when it's wrong. Exception: object properties with the wrong type are now ignored. - Made JSONRPCDispatcher parse using json::parse - The bug where 'method' must come before 'params' in the stream is fixed as a side-effect. (And the same bug in executeCommand). - Some parser crashers fixed as a side effect. e.g. https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3890 - The debug stream now prettyprints the input messages with --pretty. - Request params are attached to traces when tracing is enabled. - Fixed some bugs in tests (errors tolerated by YAMLParser, and off-by-ones in Content-Length that our null-termination was masking) - Fixed a random double-escape bug in ClangdLSPServer (it was our last use of YAMLParser!) Reviewers: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D40406 llvm-svn: 319159
* [clangd] Drop impossible completions (unavailable or inaccessible)Sam McCall2017-11-231-4/+2
| | | | | | | | | | | | Summary: (There must be some reason why D38077 didn't just do this, but I don't get it!) Reviewers: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D39836 llvm-svn: 318925
* [clangd] Use in-memory preambles in clangd.Ilya Biryukov2017-11-161-0/+2
| | | | | | | | | | | | Reviewers: klimek, bkramer, sammccall Reviewed By: sammccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D39843 llvm-svn: 318412
* [clangd] clang-format the source code. NFC.Ilya Biryukov2017-11-151-3/+2
| | | | llvm-svn: 318317
* [clangd] Support returning a limited number of completion results.Sam McCall2017-11-151-9/+9
| | | | | | | | | | | | | | | | | | | | Summary: All results are scored, we only process CodeCompletionStrings for the winners. We now return CompletionList rather than CompletionItem[] (both are valid). sortText is now based on CodeCompletionResult::orderedName (mostly the same). This is the first clangd-only completion option, so plumbing changed. It requires a small clangd patch (exposing CodeCompletionResult::orderedName). (This can't usefully be enabled yet: we don't support server-side filtering) Reviewers: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D39852 llvm-svn: 318287
* [clangd] Add rename support.Haojian Wu2017-11-091-0/+17
| | | | | | | | | | | | | | | | | | | Summary: Make clangd handle "textDocument/rename" request. The rename functionality comes from the "local-rename" sub-tool of clang-refactor. Currently clangd only supports local rename (only symbol occurrences in the main file will be renamed). Reviewers: sammccall, ilya-biryukov Reviewed By: sammccall Subscribers: cfe-commits, ioeric, arphaman, mgorny Differential Revision: https://reviews.llvm.org/D39676 llvm-svn: 317780
* [clangd] Fix initialize capabilities responseSam McCall2017-11-071-24/+26
| | | | llvm-svn: 317584
* [clangd] Add ErrorCode enum class.Haojian Wu2017-11-071-5/+9
| | | | | | | | | | | | | | Summary: Avoid using magic number in the code everywhere. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D39718 llvm-svn: 317559
* Adds a json::Expr type to represent intermediate JSON expressions.Sam McCall2017-11-061-73/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This form can be created with a nice clang-format-friendly literal syntax, and gets escaping right. It knows how to call unparse() on our Protocol types. All the places where we pass around JSON internally now use this type. Object properties are sorted (stored as std::map) and so serialization is canonicalized, with optional prettyprinting (triggered by a -pretty flag). This makes the lit tests much nicer to read and somewhat nicer to debug. (Unfortunately the completion tests use CHECK-DAG, which only has line-granularity, so pretty-printing is disabled there. In future we could make completion ordering deterministic, or switch to unittests). Compared to the current approach, it has some efficiencies like avoiding copies of string literals used as object keys, but is probably slower overall. I think the code/test quality benefits are worth it. This patch doesn't attempt to do anything about JSON *parsing*. It takes direction from the proposal in this doc[1], but is limited in scope and visibility, for now. I am of half a mind just to use Expr as the target of a parser, and maybe do a little string deduplication, but not bother with clever memory allocation. That would be simple, and fast enough for clangd... [1] https://docs.google.com/document/d/1OEF9IauWwNuSigZzvvbjc1cVS1uGHRyGTXaoy3DjqM4/edit +cc d0k so he can tell me not to use std::map. Reviewers: ioeric, malaperle Subscribers: bkramer, ilya-biryukov, mgorny, klimek Differential Revision: https://reviews.llvm.org/D39435 llvm-svn: 317486
* [clangd] Handle clangd.applyFix server-sideMarc-Andre Laperle2017-11-031-22/+52
| | | | | | | | | | | | | | | | | | | | | | | Summary: When the user selects a fix-it (or any code action with commands), it is possible to let the client forward the selected command to the server. When the clangd.applyFix command is handled on the server, it can send a workspace/applyEdit request to the client. This has the advantage that the client doesn't explicitly have to know how to handle clangd.applyFix. Therefore, the code to handle clangd.applyFix in the VS Code extension (and any other Clangd client) is not required anymore. Reviewers: ilya-biryukov, sammccall, Nebiroth, hokein Reviewed By: hokein Subscribers: ioeric, hokein, rwols, puremourning, bkramer, ilya-biryukov Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D39276 llvm-svn: 317322
* [clangd] Report an error on findDefinitions/signatureHelp on an unopened ↵Benjamin Kramer2017-10-261-12/+12
| | | | | | | | file instead of crashing. Found by clangd-fuzzer. llvm-svn: 316659
* [clangd] Don't crash on empty textDocument/didChange.Benjamin Kramer2017-10-261-0/+2
| | | | | | Found by clangd-fuzzer. llvm-svn: 316652
* [clangd] Handle exit notification (proper shutdown)Ilya Biryukov2017-10-251-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This changes the onShutdown handler to do essentially nothing (for now), and instead exits the runloop when we receive the exit notification from the client. Some clients may wait on the reply from the shutdown request before sending an exit notification. If we exit the runloop already in the shutdown request, a client might block forever. This also gives us the opportunity to do any global cleanups and/or serializations of PCH preambles to disk, but I've left that out for now. See the LSP protocol documentation for details. Reviewers: malaperle, krasimir, bkramer, sammccall, ilya-biryukov Reviewed By: malaperle, sammccall, ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D38939 llvm-svn: 316564
* [clangd] Allow to pass code completion opts to ClangdServer.Ilya Biryukov2017-10-231-1/+3
| | | | | | | | | | | | Reviewers: bkramer, krasimir, sammccall Reviewed By: krasimir Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D38731 llvm-svn: 316327
* [clangd] less boilerplate in RPC dispatchSam McCall2017-10-121-67/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Make the ProtocolHandlers glue between JSONRPCDispatcher and ClangdLSPServer generic. Eliminate small differences between methods, de-emphasize the unimportant distinction between notifications and methods. ClangdLSPServer is no longer responsible for producing a complete JSON-RPC response, just the JSON of the result object. (In future, we should move that JSON serialization out, too). Handler methods now take a context object that we may hang more functionality off in the future. Added documentation to ProtocolHandlers. Reviewers: ilya-biryukov, bkramer Reviewed By: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D38464 llvm-svn: 315577
* [clangd] Add textDocument/signatureHelpIlya Biryukov2017-10-061-0/+13
| | | | | | | | | | | | | | | | | | Summary: Makes clangd respond to a client's "textDocument/signatureHelp" request by presenting function/method overloads. Patch by Raoul Wols. Reviewers: bkramer, ilya-biryukov, krasimir Reviewed By: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D38048 llvm-svn: 315055
* [clangd] Added async API to run code completion.Ilya Biryukov2017-10-051-0/+3
| | | | | | | | | | | | | | | | | | Summary: ClangdServer now provides async code completion API. It is still used synchronously by ClangdLSPServer, more work is needed to allow processing other requests in parallel while completion (or any other request) is running. Reviewers: klimek, bkramer, krasimir Reviewed By: klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D38583 llvm-svn: 314989
* [clangd] Handle workspace/didChangeWatchedFilesMarc-Andre Laperle2017-10-021-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: The client can send notifications when it detects watched files have changed. This patch adds the protocol handling for this type of notification. For now, the notification will be passed down to the ClangdServer, but it will not be acted upon. However, this will become useful for the indexer to react to file changes. The events could also potentially be used to invalidate other caches (compilation database, etc). This change also updates the VSCode extension so that it sends the events. Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Reviewers: ilya-biryukov, Nebiroth Subscribers: ilya-biryukov Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D38422 llvm-svn: 314693
* [clangd] Command line arg to specify compile_commands.json pathIlya Biryukov2017-10-021-2/+3
| | | | | | | | | | Summary: Adds compileCommands command line argument to specify an absolute path directly to the requested compile_commands.json for flags. Reviewed By: ilya-biryukov Differential Revision: https://reviews.llvm.org/D37150 llvm-svn: 314678
* [clangd] simplify ClangdLSPServer by private-inheriting callback interfaces. NFCSam McCall2017-09-301-98/+48
| | | | | | | | | | | | | | | | Summary: There doesn't seem to be any real separation between the current three objects. Feel free to reject this if you find the current style valuable, though. (Mostly I'm just looking around for cleanups to help me understand the code). Reviewers: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D38414 llvm-svn: 314587
* Small clangd cleanups, NFCSam McCall2017-09-291-1/+1
| | | | | | | - remove old ASTUnit includes - fix typo (regiterCallbackHandlers) llvm-svn: 314532
* [clangd] LSP extension to switch between source/header fileMarc-Andre Laperle2017-09-281-0/+17
| | | | | | | | | | | | | | | | | | Summary: Small extension to LSP to allow clients to use clangd to switch between C header files and source files. Final version will use the completed clangd indexer to use the index of symbols to be able to switch from header to source file when the file names don't match. Reviewers: malaperle, krasimir, bkramer, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: ilya-biryukov, cfe-commits, arphaman Patch by: William Enright Differential Revision: https://reviews.llvm.org/D36150 llvm-svn: 314377
* [clangd] Handle InitializeParams and store rootUriMarc-Andre Laperle2017-09-271-1/+7
| | | | | | | | | | | | | | | | | | | Summary: The root Uri is the workspace location and will be useful in the context of indexing. We could also add more things to InitializeParams in order to configure Clangd for C/C++ sepecific extensions. Reviewers: ilya-biryukov, bkramer, krasimir, Nebiroth Reviewed By: ilya-biryukov Subscribers: ilya-biryukov Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D38093 llvm-svn: 314309
* [clangd] Introduced Logger interface.Ilya Biryukov2017-09-201-2/+2
| | | | | | | | | | | | | | Summary: This fixes a bunch of logging-related FIXMEs. Reviewers: bkramer, krasimir, malaperle Reviewed By: malaperle Subscribers: malaperle, klimek, cfe-commits, mgorny Differential Revision: https://reviews.llvm.org/D37972 llvm-svn: 313730
* [clangd] Add support for snippet completionsIlya Biryukov2017-09-121-1/+3
| | | | | | | | | | | | | | Enhances CompletionItemsCollector in such a way that snippet completions can be presented to the client. Enable snippet completion items by specifying -enable-snippets while invoking the clangd executable. See: https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#completion-request See: https://github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/browser/snippet.md Patch by Raoul Wols. llvm-svn: 313029
* [clangd] Use multiple working threads in clangd.Ilya Biryukov2017-08-141-2/+2
| | | | | | | | | | | | Reviewers: bkramer, krasimir, klimek Reviewed By: klimek Subscribers: arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D36261 llvm-svn: 310821
* [clangd] Run clang-format on all clangd sources. NFC.Ilya Biryukov2017-08-021-7/+11
| | | | llvm-svn: 309801
* [clangd] Add ':' to completion trigger characters.Ilya Biryukov2017-07-311-1/+1
| | | | | | | | | | | | | | | | Summary: Without it we don't get completion requests from VSCode after nested name qualifiers (e.g. after 'std::'). Reviewers: krasimir, bkramer Reviewed By: krasimir Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D35986 llvm-svn: 309550
* [clangd] Allow specifying -resource-dirKrasimir Georgiev2017-07-191-2/+3
| | | | | | | | | | | | | | | | Summary: This patch allows clangd to specify its -resource-dir. Reviewers: bkramer, klimek Reviewed By: bkramer Subscribers: cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D35617 llvm-svn: 308486
* [clangd] Add support for per-file extra flagsKrasimir Georgiev2017-07-061-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds the ability to specify user-defined extra flags per opened file through the LSP layer. This is a non-standard extension to the protocol. I've already created a feature request about it for upstream lsp: https://github.com/Microsoft/language-server-protocol/issues/255 The particular use-case is ycmd, which has a python script for figuring out extra flags per file: https://github.com/Valloric/ycmd#flagsforfile-filename-kwargs- Reviewers: ilya-biryukov, klimek, bkramer Reviewed By: ilya-biryukov Subscribers: cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D34947 llvm-svn: 307241
* [clangd] Add "Go to Declaration" functionalityMarc-Andre Laperle2017-06-281-1/+23
| | | | | | | | | | | | | | | | Summary: This change allows to navigate to most identifiers' declarations in code. This is a first step towards implementing "Go to Definition". It reuses clangIndex in order to detect which occurrences corresponds to the position requested. The occurrences' Decls are then used to generate locations suitable for navigating to the declarations. Reviewers: krasimir, bkramer, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: cfe-commits, mgorny Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D34269 llvm-svn: 306558
* [clangd] Store references instead of unique_ptrs in ClangdServer.Ilya Biryukov2017-06-131-16/+9
| | | | | | | | | | | | | | | | Summary: ClangdServer owned objects passed to it in constructor for no good reason. Lots of stuff was moved from the heap to the stack thanks to this change. Reviewers: krasimir Reviewed By: krasimir Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D34148 llvm-svn: 305298
* [clangd] Mark results of clangd requests with a tag provided by the ↵Ilya Biryukov2017-05-301-3/+3
| | | | | | | | | | | | | | | | | | | | FileSystemProvider. Summary: This allows an implementation of FileSystemProvider that can track which vfs::FileSystem were used for each of the requests. Reviewers: bkramer, krasimir Reviewed By: bkramer Subscribers: klimek, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D33678 llvm-svn: 304214
* [clangd] Allow to use vfs::FileSystem for file accesses.Ilya Biryukov2017-05-261-0/+1
| | | | | | | | | | | | | | | | Summary: Custom vfs::FileSystem is currently used for unit tests. This revision depends on https://reviews.llvm.org/D33397. Reviewers: bkramer, krasimir Reviewed By: bkramer, krasimir Subscribers: klimek, cfe-commits, mgorny Differential Revision: https://reviews.llvm.org/D33416 llvm-svn: 303977
* [clangd] Refactor ProtocolHandlers to decouple them from ClangdLSPServerIlya Biryukov2017-05-161-13/+181
| | | | | | | | | | | | | | | | | | | | | | | | Summary: A refactoring to decouple ProtocolHandlers and Language Server input parsing loop from the ClangdLSPServer. The input parsing was extracted from `main` to a function(runLanguageServerLoop). ProtocolHandlers now provide an interface to handle various LSP methods, this interface is used by ClangdLSPServer. Methods for code formatting were moved from ProtocolHandlers to ClangdServer. ClangdLSPServer now provides a cleaner interface that only runs Language Server input loop. Reviewers: bkramer, krasimir Reviewed By: krasimir Subscribers: cfe-commits, klimek Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D33201 llvm-svn: 303173
* Restored r303067 and fixed failing test.Ilya Biryukov2017-05-161-0/+100
| | | | | | | | | | | | | | | | | | | | | Summary: This commit restores r303067(reverted by r303094) and fixes the 'formatting.test' failure. The failure is due to destructors of `ClangdLSPServer`'s fields(`FixItsMap` and `FixItsMutex`) being called before destructor of `Server`. It led to the worker thread calling `consumeDiagnostics` after `FixItsMutex` and `FixItsMap` destructors were called. Also, clangd is now run with '-run-synchronously' flag in 'formatting.test'. Reviewers: bkramer, krasimir Reviewed By: krasimir Subscribers: mgorny, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D33233 llvm-svn: 303151
* Revert "[ClangD] Refactor clangd into separate components"Adam Nemet2017-05-151-100/+0
| | | | | | | | | | This reverts commit r303067. Caused http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/34305/ And even after Simon's fix there is still a test failure. llvm-svn: 303094
* [ClangD] Refactor clangd into separate componentsIlya Biryukov2017-05-151-0/+100
Summary: Major refactoring to split LSP implementation, Clang API calls and threading(mostly synchronization) Reviewers: bkramer, krasimir Reviewed By: bkramer Subscribers: cfe-commits, mgorny, klimek Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D33047 llvm-svn: 303067
OpenPOWER on IntegriCloud