summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/ClangdServer.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [clangd] NFC: Migrate to LLVM STLExtras API where possibleKirill Bobyrev2018-10-071-8/+6
| | | | | | | | | | | | | | This patch improves readability by migrating `std::function(ForwardIt start, ForwardIt end, ...)` to LLVM's STLExtras range-based equivalent `llvm::function(RangeT &&Range, ...)`. Similar change in Clang: D52576. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D52650 llvm-svn: 343937
* [clangd] expose MergedIndex classSam McCall2018-10-041-7/+4
| | | | | | | | | | | | | | Summary: This allows inheriting from it, so index() can ga away and allowing TestTU::index) to be fixed. Reviewers: ioeric Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52250 llvm-svn: 343780
* [clangd] Cache FS stat() calls when building preamble.Eric Liu2018-10-021-9/+4
| | | | | | | | | | | | | | | | | | | | Summary: The file stats can be reused when preamble is reused (e.g. code completion). It's safe to assume that cached status is not outdated as we assume preamble files to remain unchanged. On real file system, this made code completion ~20% faster on a measured file (with big preamble). The preamble build time doesn't change much. Reviewers: sammccall, ilya-biryukov Reviewed By: sammccall Subscribers: mgorny, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52419 llvm-svn: 343576
* [clangd] Get rid of Decls parameter in indexMainDecls. NFCEric Liu2018-09-181-1/+1
| | | | | | It's already available in ParsedAST. llvm-svn: 342473
* [clangd] Merge ClangdServer::DynamicIndex into FileIndex. NFC.Eric Liu2018-09-181-59/+20
| | | | | | | | | | | | | | | | | | | | Summary: FileIndex now provides explicit interfaces for preamble and main file updates. This avoids growing parameter list when preamble and main symbols diverge further (e.g. D52078). This also gets rid of the hack in `indexAST` that inferred main file index based on `TopLevelDecls`. Also separate `indexMainDecls` from `indexAST`. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52222 llvm-svn: 342460
* [clangd] Allow all LSP methods to signal cancellation via $/cancelRequestSam McCall2018-09-131-7/+3
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: The cancelable scopes are managed by JSONRPCDispatcher so that all Handlers run in cancelable contexts. (Previously ClangdServer did this, for code completion only). Cancellation request processing is therefore also in JSONRPCDispatcher. (Previously it was in ClangdLSPServer). This doesn't actually make any new commands *respect* cancellation - they'd need to check isCancelled() and bail out. But it opens the door to doing this incrementally, and putting such logic in common machinery like TUScheduler. I also rewrote the ClangdServer class/threading comments because I wanted to add to it and I got carried away. Reviewers: ilya-biryukov, kadircet Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D52004 llvm-svn: 342135
* [clangd] Simplify cancellation public APISam McCall2018-09-131-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Task is no longer exposed: - task cancellation is hidden as a std::function - task creation returns the new context directly - checking is via free function only, with no way to avoid the context lookup The implementation is essentially the same, but a bit terser as it's hidden. isCancelled() is now safe to use outside any task (it returns false). This will leave us free to sprinkle cancellation in e.g. TUScheduler without needing elaborate test setup, and lets callers that don't cancel "just work". Updated the docs to describe the new expected use pattern. One thing I noticed: there's nothing async-specific about the cancellation. Async tasks can be cancelled from any thread (typically the one that created them), sync tasks can be cancelled from any *other* thread in the same way. So the docs now refer to "long-running" tasks instead of async ones. Updated usage in code complete, without any structural changes. I didn't update all the names of the helpers in ClangdLSPServer (these will likely be moved to JSONRPCDispatcher anyway). Reviewers: ilya-biryukov, kadircet Subscribers: ioeric, MaskRay, jkorous, arphaman, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D51996 llvm-svn: 342130
* [clangd] Add xrefs LSP boilerplate implementation.Sam McCall2018-09-051-0/+12
| | | | | | | | | | Reviewers: ilya-biryukov, ioeric Subscribers: MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50896 llvm-svn: 341462
* [clangd] SymbolOccurrences -> Refs and cleanupSam McCall2018-09-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: A few things that I noticed while merging the SwapIndex patch: - SymbolOccurrences and particularly SymbolOccurrenceSlab are unwieldy names, and these names appear *a lot*. Ref, RefSlab, etc seem clear enough and read/format much better. - The asymmetry between SymbolSlab and RefSlab (build() vs freeze()) is confusing and irritating, and doesn't even save much code. Avoiding RefSlab::Builder was my idea, but it was a bad one; add it. - DenseMap<SymbolID, ArrayRef<Ref>> seems like a reasonable compromise for constructing MemIndex - and means many less wasted allocations than the current DenseMap<SymbolID, vector<Ref*>> for FileIndex, and none for slabs. - RefSlab::find() is not actually used for anything, so we can throw away the DenseMap and keep the representation much more compact. - A few naming/consistency fixes: e.g. Slabs,Refs -> Symbols,Refs. Reviewers: ioeric Subscribers: ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51605 llvm-svn: 341368
* [clangd] Some nitpicking around the new split (preamble/main) dynamic indexSam McCall2018-09-031-17/+44
| | | | | | | | | | | | | | | | | | | | | | Summary: - DynamicIndex doesn't implement ParsingCallbacks, to make its role clearer. ParsingCallbacks is a separate object owned by the receiving TUScheduler. (I tried to get rid of the "index-like-object that doesn't implement index" but it was too messy). - Clarified(?) docs around DynamicIndex - fewer details up front, more details inside. - Exposed dynamic index from ClangdServer for memory monitoring and more direct testing of its contents (actual tests not added here, wanted to get this out for review) - Removed a redundant and sligthly confusing filename param in a callback Reviewers: ilya-biryukov Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51221 llvm-svn: 341325
* [clangd] Handle errors before checking for cancelltionIlya Biryukov2018-09-031-3/+2
| | | | | | To avoid hitting assertions in llvm::Expected destructor. llvm-svn: 341319
* [clangd] Run SignatureHelp using an up-to-date preamble, waiting if needed.Sam McCall2018-08-301-2/+7
| | | | | | | | | | | | | | Summary: After code completion inserts a header, running signature help using the old preamble will usually fail. So we add support for consistent preamble reads. Reviewers: ilya-biryukov Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51438 llvm-svn: 341076
* [clangd] Add some trace::Spans. NFCIlya Biryukov2018-08-281-0/+1
| | | | llvm-svn: 340815
* [clangd] Initial cancellation mechanism for LSP requests.Kadir Cetinkaya2018-08-241-3/+10
| | | | | | | | | | | | Reviewers: ilya-biryukov, ioeric, hokein Reviewed By: ilya-biryukov Subscribers: mgorny, ioeric, MaskRay, jkorous, arphaman, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50502 llvm-svn: 340607
* [clangd] Speculative code completion index request before Sema is run.Eric Liu2018-08-241-5/+31
| | | | | | | | | | | | | | | | | | | | | | | | Summary: For index-based code completion, send an asynchronous speculative index request, based on the index request for the last code completion on the same file and the filter text typed before the cursor, before sema code completion is invoked. This can reduce the code completion latency (by roughly latency of sema code completion) if the speculative request is the same as the one generated for the ongoing code completion from sema. As a sequence of code completions often have the same scopes and proximity paths etc, this should be effective for a number of code completions. Trace with speculative index request:{F6997544} Reviewers: hokein, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: javed.absar, jfb, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D50962 llvm-svn: 340604
* [clangd] Make FileIndex aware of the main fileIlya Biryukov2018-08-221-17/+33
| | | | | | | | | | | | | | | | | | | | | Summary: It was previously only indexing the preamble decls. The new implementation will index both the preamble and the main AST and report both sets of symbols, preferring the ones from the main AST whenever the symbol is present in both. The symbols in the main AST slab always store all information available in the preamble symbols, possibly adding more, e.g. definition locations. Reviewers: hokein, ioeric Reviewed By: ioeric Subscribers: kadircet, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50889 llvm-svn: 340404
* [clangd] Add callbacks on parsed AST in addition to parsed preamblesIlya Biryukov2018-08-221-8/+22
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Will be used for updating the dynamic index on updates to the open files. Currently we collect only information coming from the preamble AST. This has a bunch of limitations: - Dynamic index misses important information from the body of the file, e.g. locations of definitions. - XRefs cannot be collected at all, since we can only obtain full information for the current file (preamble is parsed with skipped function bodies, therefore not reliable). This patch only adds the new callback, actually updates to the index will be done in a follow-up patch. Reviewers: hokein Reviewed By: hokein Subscribers: kadircet, javed.absar, ioeric, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50847 llvm-svn: 340401
* [clangd] Fetch documentation from the Index during signature helpIlya Biryukov2018-08-171-3/+4
| | | | | | | | | | | | | | | | Summary: Sema can only be used for documentation in the current file, other doc comments should be fetched from the index. Reviewers: hokein, ioeric, kadircet Reviewed By: hokein, kadircet Subscribers: MaskRay, jkorous, mgrang, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50727 llvm-svn: 340005
* [clangd] Extract FileSystemProvider into a separate header. NFCSam McCall2018-07-121-4/+0
| | | | | | | | | | | | Reviewers: sammccall Reviewed By: sammccall Subscribers: mgorny, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D49142 llvm-svn: 336909
* [clangd] Upgrade logging facilities with levels and formatv.Sam McCall2018-07-111-3/+3
| | | | | | | | | | | | | | | | | | | | | | Summary: log() is split into four functions: - elog()/log()/vlog() have different severity levels, allowing filtering - dlog() is a lazy macro which uses LLVM_DEBUG - it logs to the logger, but conditionally based on -debug-only flag and is omitted in release builds All logging functions use formatv-style format strings now, e.g: log("Could not resolve URI {0}: {1}", URI, Result.takeError()); Existing log sites have been split between elog/log/vlog by best guess. This includes a workaround for passing Error to formatv that can be simplified when D49170 or similar lands. Subscribers: ilya-biryukov, javed.absar, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D49008 llvm-svn: 336785
* [clangd] Implementation of textDocument/documentSymbolMarc-Andre Laperle2018-07-051-0/+12
| | | | | | | | | | | | | | | | | Summary: An AST-based approach is used to retrieve the document symbols rather than an in-memory index query. The index is not an ideal fit to achieve this because of the file-centric query being done here whereas the index is suited for project-wide queries. Document symbols also includes more symbols and need to keep the order as seen in the file. Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Subscribers: tomgr, ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47846 llvm-svn: 336386
* [clangd] Replace UniqueFunction with llvm::unique_function.Benjamin Kramer2018-07-031-1/+1
| | | | | | One implementation of this ought to be enough for everyone. llvm-svn: 336228
* [clangd] Incorporate transitive #includes into code complete proximity scoring.Sam McCall2018-07-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Summary: We now compute a distance from the main file to the symbol header, which is a weighted count of: - some number of #include traversals from source file --> included file - some number of FS traversals from file --> parent directory - some number of FS traversals from parent directory --> child file/dir This calculation is performed in the appropriate URI scheme. This means we'll get some proximity boost from header files in main-file contexts, even when these are in different directory trees. This extended file proximity model is not yet incorporated in the index interface/implementation. Reviewers: ioeric Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D48441 llvm-svn: 336177
* [clangd] ClangdServer::codeComplete return CodeCompleteResult, not LSP struct.Sam McCall2018-07-021-7/+3
| | | | | | | | | | | | | | | | | | | | Summary: This provides more structured information that embedders can use for rendering. ClangdLSPServer continues to call render(), so NFC. The patch is: - trivial changes to ClangdServer/ClangdLSPServer - mostly-mechanical updates to CodeCompleteTests etc for the new API - new direct tests of render() in CodeCompleteTests - tiny cleanups to CodeCompletionItem (operator<< and missing initializers) Reviewers: ioeric Subscribers: ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D48821 llvm-svn: 336094
* [clangd] codeComplete returns more structured completion items, LSP. NFC.Sam McCall2018-06-291-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: LSP has some presentational fields with limited semantics (e.g. 'detail') and doesn't provide a good place to return information like namespace. Some places where more detailed information is useful: - tools like quality analysis - alternate frontends that aren't strictly LSP - code completion unit tests In this patch, ClangdServer::codeComplete still return LSP CompletionList, but I plan to switch that soon (should be a no-op for ClangdLSPServer). Deferring this makes it clear that we don't change behavior (tests stay the same) and also keeps the API break to a small patch which can be reverted. Reviewers: ioeric Subscribers: ilya-biryukov, MaskRay, cfe-commits, jkorous Differential Revision: https://reviews.llvm.org/D48762 llvm-svn: 335980
* [clangd] Use default clang-format styles.Eric Liu2018-06-261-1/+2
| | | | llvm-svn: 335598
* [clangd] Use workspace root path as hint path for resolving URIs in ↵Eric Liu2018-06-191-5/+11
| | | | | | | | | | | | | | | | | | workspace/symbol Summary: Some URI schemes require a hint path to be provided, and workspace root path seems to be a good fit. Reviewers: sammccall, malaperle Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D48290 llvm-svn: 335035
* [clangd] Customizable URI schemes for dynamic index.Eric Liu2018-06-151-1/+2
| | | | | | | | | | | | | | | | | Summary: This allows dynamic index to have consistent URI schemes with the static index which can have customized URI schemes, which would make file proximity scoring based on URIs easier. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47931 llvm-svn: 334809
* [clangd] Move caching of compile args out of ClangdServer.Ilya Biryukov2018-06-131-10/+18
| | | | | | | | | | | | | | | | | | | | | Summary: Caching is now handled by ClangdLSPServer and hidden behind the GlobalCompilationDatabase interface. This simplifies ClangdServer. This change also removes the SkipCache flag from addDocument, which is now obsolete. No behavioral changes are intended, the clangd binary still caches the compile commands on the first read. Reviewers: sammccall Reviewed By: sammccall Subscribers: mgorny, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D48068 llvm-svn: 334585
* [clangd] Fix using the incorrect Index for go-to-definition.Haojian Wu2018-06-071-1/+1
| | | | | | | | | | Reviewers: sammccall Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47869 llvm-svn: 334176
* [clangd] Remove unused variablesMarc-Andre Laperle2018-06-051-10/+6
| | | | | | | | | | Summary: Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Subscribers: klimek, ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47737 llvm-svn: 334018
* [clangd] Hover should return null when not hovering over anything.Sam McCall2018-06-041-2/+3
| | | | | | | | | | | | Summary: Also made JSON serialize Optional<T> to simplify this. Reviewers: ioeric Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47701 llvm-svn: 333881
* [clangd] Keep only a limited number of idle ASTs in memoryIlya Biryukov2018-06-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Summary: After this commit, clangd will only keep the last 3 accessed ASTs in memory. Preambles for each of the opened files are still kept in memory to make completion and AST rebuilds fast. AST rebuilds are usually fast enough, but having the last ASTs in memory still considerably improves latency of operations like findDefinition and documeneHighlight, which are often sent multiple times a second when moving around the code. So keeping some of the last accessed ASTs in memory seems like a reasonable tradeoff. Reviewers: sammccall Reviewed By: sammccall Subscribers: malaperle, arphaman, klimek, javed.absar, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47063 llvm-svn: 333737
* [clangd] Build index on preamble changes instead of the AST changesIlya Biryukov2018-05-241-6/+9
| | | | | | | | | | | | | | | | | | | | | Summary: This is more efficient and avoids data races when reading files that come from the preamble. The staleness can occur when reading a file from disk that changed after the preamble was built. This can lead to crashes, e.g. when parsing comments. We do not to rely on symbols from the main file anyway, since any info that those provide can always be taken from the AST. Reviewers: ioeric, sammccall Reviewed By: ioeric Subscribers: malaperle, klimek, javed.absar, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47272 llvm-svn: 333196
* [clangd] Fix a typo. NFCIlya Biryukov2018-05-221-1/+1
| | | | llvm-svn: 332978
* [clangd] Populate #include insertions as additional edits in completion items.Eric Liu2018-05-151-0/+1
| | | | | | | | | | | | | | | | | | | | Summary: o Remove IncludeInsertion LSP command. o Populate include insertion edits synchromously in completion items. o Share the code completion compiler instance and precompiled preamble to get existing inclusions in main file. o Include insertion logic lives only in CodeComplete now. o Use tooling::HeaderIncludes for inserting new includes. o Refactored tests. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D46497 llvm-svn: 332363
* [clangd] Remove LSP command-based #include insertion.Eric Liu2018-05-151-60/+0
| | | | | | | | | | | | | | | | | Summary: clangd will populate #include insertions as addtionalEdits in completion items. The code completion tests in ClangdServerTest will be added back in D46497. Reviewers: ilya-biryukov, sammccall Reviewed By: ilya-biryukov Subscribers: klimek, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D46676 llvm-svn: 332362
* [clangd] Using index for GoToDefinition.Haojian Wu2018-04-301-3/+3
| | | | | | | | | | | | | | | | | | | Summary: This patch adds index support for GoToDefinition -- when we don't get the definition from local AST, we query our index (Static&Dynamic) index to get it. Since we currently collect top-level symbol in the index, it doesn't support all cases (e.g. class members), we will extend the index to include more symbols in the future. Reviewers: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits Differential Revision: https://reviews.llvm.org/D45717 llvm-svn: 331189
* [clangd] Fix unicode handling, using UTF-16 where LSP requires it.Sam McCall2018-04-271-7/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The Language Server Protocol unfortunately mandates that locations in files be represented by line/column pairs, where the "column" is actually an index into the UTF-16-encoded text of the line. (This is because VSCode is written in JavaScript, which is UTF-16-native). Internally clangd treats source files at UTF-8, the One True Encoding, and generally deals with byte offsets (though there are exceptions). Before this patch, conversions between offsets and LSP Position pretended that Position.character was UTF-8 bytes, which is only true for ASCII lines. Now we examine the text to convert correctly (but don't actually need to transcode it, due to some nice details of the encodings). The updated functions in SourceCode are the blessed way to interact with the Position.character field, and anything else is likely to be wrong. So I also updated the other accesses: - CodeComplete needs a "clang-style" line/column, with column in utf-8 bytes. This is now converted via Position -> offset -> clang line/column (a new function is added to SourceCode.h for the second conversion). - getBeginningOfIdentifier skipped backwards in UTF-16 space, which is will behave badly when it splits a surrogate pair. Skipping backwards in UTF-8 coordinates gives the lexer a fighting chance of getting this right. While here, I clarified(?) the logic comments, fixed a bug with identifiers containing digits, simplified the signature slightly and added a test. This seems likely to cause problems with editors that have the same bug, and treat the protocol as if columns are UTF-8 bytes. But we can find and fix those. Reviewers: hokein Subscribers: klimek, ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D46035 llvm-svn: 331029
* [clangd] Implementation of workspace/symbol requestMarc-Andre Laperle2018-04-231-0/+6
| | | | | | | | | | | | | | | | | | | | | | | Summary: This is a basic implementation of the "workspace/symbol" request which is used to find symbols by a string query. Since this is similar to code completion in terms of result, this implementation reuses the "fuzzyFind" in order to get matches. For now, the scoring algorithm is the same as code completion and improvements could be done in the future. The index model doesn't contain quite enough symbols for this to cover common symbols like methods, enum class enumerators, functions in unamed namespaces, etc. The index model will be augmented separately to achieve this. Reviewers: sammccall, ilya-biryukov Reviewed By: sammccall Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits Differential Revision: https://reviews.llvm.org/D44882 llvm-svn: 330637
* [clangd] Allow using customized include path in URI.Haojian Wu2018-04-091-0/+7
| | | | | | | | | | | | | | | | | | | Summary: Calculating the include path from absolute file path does not always work for all build system, e.g. bazel uses symlink as the build working directory. The absolute file path from editor and clang is diverged from each other. We need to address it properly in build sysmtem integration. This patch worksarounds the issue by providing a hook in URI which allows clients to provide their customized include path. Reviewers: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits Differential Revision: https://reviews.llvm.org/D45426 llvm-svn: 329578
* Make positionToOffset return llvm::Expected<size_t>Simon Marchi2018-03-211-7/+13
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: To implement incremental document syncing, we want to verify that the ranges provided by the front-end are valid. Currently, positionToOffset deals with invalid Positions by returning 0 or Code.size(), which are two valid offsets. Instead, return an llvm:Expected<size_t> with an error if the position is invalid. According to the LSP, if the character value exceeds the number of characters of the given line, it should default back to the end of the line. It makes sense in some contexts to have this behavior, and does not in other contexts. The AllowColumnsBeyondLineLength parameter allows to decide what to do in that case, default back to the end of the line, or return an error. Reviewers: ilya-biryukov Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D44673 llvm-svn: 328100
* Move DraftMgr from ClangdServer to ClangdLSPServerSimon Marchi2018-03-161-38/+5
| | | | | | | | | | | | | | | | | | | | Summary: This patch moves the draft manager closer to the edge of Clangd, from ClangdServer to ClangdLSPServer. This will make it easier to implement incremental document sync, by making ClangdServer only deal with complete documents. As a result, DraftStore doesn't have to deal with versioning, and thus its API can be simplified. It is replaced by a StringMap in ClangdServer holding a current version number for each file. Signed-off-by: Simon Marchi <simon.marchi@ericsson.com> Subscribers: klimek, mgorny, ilya-biryukov, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D44408 llvm-svn: 327711
* [clangd] Use Contents from inputs in codeComplete and signatureHelpSimon Marchi2018-03-141-13/+10
| | | | | | | | | | | | | | | Summary: ClangdServer::{codeComplete,signatureHelp} both use the Contents from the draft manager. Since we want to move the draft manager from ClangdServer to ClangdLSPServer, this patch changes those methods to find the file contents from InputsAndPreamble, which contains the source passed in previously. Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D44484 llvm-svn: 327550
* [clangd] Don't expose vfs in TUScheduler::runWithPreamble.Ilya Biryukov2018-03-141-4/+2
| | | | | | | | | | | | | | | | Summary: It was previously an easy way to concurrently access a mutable vfs, which is a recipe for disaster. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, jkorous-apple, cfe-commits, ioeric Differential Revision: https://reviews.llvm.org/D44463 llvm-svn: 327537
* [clangd] Remove forceReparse, add a flag to addDocument insteadIlya Biryukov2018-03-141-47/+32
| | | | | | | | | | | | | | Summary: To make the removal of DraftMgr from ClangdServer easier (D44408). Reviewers: sammccall, simark Reviewed By: sammccall, simark Subscribers: simark, klimek, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D44462 llvm-svn: 327532
* [clangd] Remove Tagged and some related APIs from ClangdServer.Sam McCall2018-03-121-108/+72
| | | | | | | | | | | | Context can do what Tagged was intended to support (snapshot filesystems), and less intrusively. getTaggedFileSystem() no longer needs a filename. Cleanups while here: - code-complete now returns errors as Expected, like other functions - added an alias Callback<T> for the usual callback function type llvm-svn: 327344
* [clangd] Revamp handling of diagnostics.Ilya Biryukov2018-03-121-2/+1
| | | | | | | | | | | | | | | | Summary: The new implementation attaches notes to diagnostic message and shows the original diagnostics in the message of the note. Reviewers: hokein, ioeric, sammccall Reviewed By: sammccall Subscribers: klimek, mgorny, cfe-commits, jkorous-apple Differential Revision: https://reviews.llvm.org/D44142 llvm-svn: 327282
* [clangd] Fix -Wpedantic warning, NFC.Haojian Wu2018-03-061-1/+1
| | | | llvm-svn: 326778
* [clangd] Sort includes when formatting code or inserting new includes.Eric Liu2018-03-061-8/+19
| | | | | | | | | | Reviewers: hokein, ilya-biryukov Subscribers: klimek, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D44138 llvm-svn: 326773
OpenPOWER on IntegriCloud