Commit Graph

1605 Commits

Author SHA1 Message Date
Fangrui Song
0fe8a16504 Infer -target and --driver-mode from argv[0]
Fix #511
2019-10-31 22:31:03 -07:00
Fangrui Song
5935db10fd Fix some clang-tidy warnings
Incorporated some fixes by Daniel Chabrowski (#467)
2019-10-10 19:24:44 -07:00
Fangrui Song
2bffff7b0b Add initialization option completion.placeholder; change client.snippetSupport: false to drop ( and <
* client.snippetSupport: false => `foo`
* client.snippetSupport: true
  + completion.placeholder: false => `foo($1)$0` `bar<$1>()$0`
  + completion.placeholder: true => `foo(${1:int a}, ${2:int b})$0` `bar<${1:typename T}>()$0`

Note, client.snippetSupport is always false if the client does not support snippets.

Close #412
2019-10-06 23:54:45 -07:00
Fangrui Song
aa9668a8fc completion: don't reuse cache if the buffer line has changed
Fix emacs-ccls#54
2019-09-26 23:25:09 -07:00
Fangrui Song
0c6be472ce project: strip -Xclang <arg> 2019-09-11 19:05:04 -07:00
Fangrui Song
b3d694b8bd indexer: disable warnings and skip processed function bodies
Adapt clang rC370337: removal of createIndexingAction and WrappingIndexAction
2019-08-21 18:59:41 -07:00
Fangrui Song
65f86d0498 indexer: llvm::sys::fs::UniqueID -> clang::FileID
Fix a minor issue that an empty included file is not recorded.

Note, we need to skip invalid uid2lid_and_path because
otherwise lid2path may contain invalid entries with lid: 0,
which will cause the file entry with file_id 0 to have an empty path.
2019-08-21 23:46:02 -07:00
Fangrui Song
0f0e679edb indexer: delete redundant consumeFile 2020-04-21 21:43:56 -07:00
Fangrui Song
6717986541 Adapt llvmorg-11-init-1314-g777180a32b6: StringRef's conversion to std::string is now explicit
For compatibility with LLVM 7, the call sites have to be a bit verbose.
2020-01-29 00:29:06 -08:00
Fangrui Song
61a1071634 💥 Rename FunctionName -> functionName, VarName -> var_name 2019-08-22 10:12:03 -07:00
Fangrui Song
62fbde7873 textDocument/definition: don't jump to the type definition 2019-08-22 02:24:20 -07:00
Fangrui Song
50d7fbc235 project: allow absolute compilationDatabaseDirectory
Fix #466
2019-08-16 19:34:11 -07:00
Fangrui Song
17dc4a6ecc Construct SourceManager with UserFilesAreVolatile
Fix #235. Close #453

In clang, it may be worth generalizing UserFilesAreVolatile (introduced in rC160074) to FilesAreVolatile.
2019-07-30 21:18:34 -07:00
Fangrui Song
a43e51f3bf project: improve ComputeGuessScore heuristics 2019-07-20 06:13:53 -07:00
Fangrui Song
ab6498e2ff Support indexing non-existent files in index.onChange:true mode 2019-07-20 01:16:15 -07:00
Fangrui Song
86a93b2d71 $ccls/fileInfo: optionally dump dependencies, includes and skipped_ranges 2019-07-20 02:24:07 -07:00
Riatre Foo
3dac492025 Change RequestId::value from int to std::string to allow non-numeric IDs. 2019-07-16 14:39:35 +08:00
Fangrui Song
c728fe9795 project: support %cu directive and strip -M* options 2019-06-27 19:11:38 -07:00
Fangrui Song
ab4b4efcaf pipeline: report changed arg 2019-06-27 01:41:25 -07:00
TÖRÖK Attila
b7027f89e5 threaded_queue.hh: fix -Wpessimizing-move (#409) 2019-06-18 08:45:20 +02:00
Fangrui Song
20883c047c utils.hh: work around MSVC STL bug 2019-06-17 23:42:48 -07:00
Fangrui Song
0d911077f4 Set Diag::concerned if any of its Notes is concerned 2019-05-12 09:03:58 -07:00
Fangrui Song
fd3e82b682 Refactor FindEntry and use best-fit .ccls
Fixes an issue with hierarchical .ccls found by Riatre in #384
2019-04-29 08:44:52 -07:00
Fangrui Song
94727b7eae JsonWriter: write "null" if VersionedTextDocumentIdentifier.version is null
Fix #387
2019-04-30 06:22:32 -07:00
Riatre Foo
aa2f55eb2b Append '/' before populating folder.dot_ccls 2019-04-28 19:11:10 +08:00
Fangrui Song
0951004370 Set RetainCommentsFromSystemHeaders to true
Note with -fretain-comments-from-system-headers, the .gch of bits/stdc++.h becomes larger by 1%, but that is fine.

And improve comment handling in textDocument/hover

Fix #373
2019-04-11 22:26:07 -07:00
Fangrui Song
3a364c868b Set RetainRemappedFileBuffers to true
Reported by David Welch in #350.

This fixes double-free of llvm::MemoryBuffer when parsing fails.
2019-03-29 07:48:58 -07:00
Fangrui Song
4c871d9783 Add error checking of object deserialization; ignore non-object initializationOptions 2019-03-29 06:54:41 -07:00
Fangrui Song
4808ccb32c Add missing headers to adapt llvmorg-11-init-5501-g213aea4c583 and llvmorg-11-init-5528-gd7c5037e6b9 2020-03-12 08:35:59 -07:00
Fangrui Song
b0d42ad8f2 Adapt llvmorg-10-init-12036-g3b9715cb2193: handleDeclOccurence -> handleDeclOccurrence 2019-12-16 22:11:31 -08:00
Fangrui Song
a858567686 Adapt rL364464: clang::FrontendAction::Execute returns llvm::Error instead of bool 2019-06-27 01:10:04 -07:00
Fangrui Song
aab9dd6642 Simplify: hide unrelated options 2019-05-08 07:45:17 -07:00
Fangrui Song
34c5954420 Adapt clang rC358696: removal of OutputIsBinary 2019-04-18 19:16:24 -07:00
Fangrui Song
1066548dba Adapt D73392 - split of llvm/Support/Allocator.h 2020-01-25 09:57:16 -08:00
Fangrui Song
f1cbf8d550 Adapt clang rC357037: removal of setVirtualFileSystem 2019-03-26 18:42:48 -07:00
Fangrui Song
17eaca8a02 Add initialization option index.initialNoLinkage: false
By default, the background indexer doesn't handle names of no linkage.
They are indexed when their files are opened. This saves memory and
makes cache files smaller.
2019-03-24 23:42:00 -07:00
Paul Smith
b6155ddf73 Enhance the output of --version with Git describe results. (#342) 2019-03-23 20:24:10 -04:00
Fangrui Song
7bee63d0e0 Change containers of Query*::Def fields from std::vector to ccls::Vec
Query*::Def contain several immutable std::vector fields. Change them to
ccls::Vec to save bytes which were wasted by `capacity`.
2019-03-15 09:33:44 -07:00
Fangrui Song
e576df4f6f Add initialization option index.name.suppressUnwrittenScope (default: false) 2019-03-10 08:55:01 -07:00
Fangrui Song
dbf7d8eb41 If the workspace folder is a symlink, convert paths relative to it (#314)
If the workspace folder is a symlink and the client doesn't follow it.
Treat /tmp/symlink/ as canonical and convert every /tmp/real/ path to
/tmp/symlink/.
2019-03-10 00:27:50 -08:00
Fangrui Song
7c70c0662f cmake: use {LLVM,Clang}Config.cmake
Combined Daan De Meyer's #227 with other simplification

* USE_SHARED_LLVM is deleted in favor of LLVM_LINK_LLVM_DYLIB
* LLVM_ENABLE_RTTI is deleted as it is provided by LLVMConfig.cmake
* Only direct Clang/LLVM dependencies are required in target_link_libraries
* Restrict -DCLANG_RESOURCE_DIRECTORY= to src/utils.cc
2019-03-09 19:45:37 -08:00
Fangrui Song
5d27ac9f34 Add excludeRole to documentSymbol and override declaration's range/selectionRange with definition's 2019-03-08 23:37:08 -08:00
Fangrui Song
9ca095f49e Misc 2019-03-02 18:18:02 -08:00
Fangrui Song
6a3cff6e50 Make clang.excludeArgs accept glob patterns 2019-03-04 18:21:53 -08:00
Fangrui Song
6c7b868556 stdin: synthesize an "exit" NotificationMessage in abnormal termination 2019-03-04 06:52:07 -08:00
Fangrui Song
beff1f6e89 textDocument/rename: mitigate edits in the same place and edits in macro replacement
Mitigate edits in the same place (#294) and:

// textDocument/rename on `f`
void f();
void g() { m(); } // incorrectly rewrote m() before
2019-03-01 18:35:13 -08:00
Fangrui Song
74432a641d working_files: normalize \r\n and \n to \n
Clients may normalize end-of-line sequences, thus cause a mismatch
between index_lines and buffer_lines.

Thanks to CXuesong for reporting this issue!
2019-03-01 17:30:53 -08:00
Fangrui Song
dcaa5a07af Change Pos::line from int16_t to uint16_t
This allows representing line 0 ~ 65535.
2019-02-23 19:17:26 +08:00
Fangrui Song
9dea14e783 Make hover more detailed (e.g. include inheritance info) 2019-02-22 23:49:37 +08:00
Fangrui Song
f35883f9b4 indexer: index TemplateTypeParmDecl and ParmVarDecl in declarations for clang >= 9
Index ParmVarDecl in declarations if index.parametersInDeclarations is true

And support some unhandled Decl::Kind
2019-02-22 10:59:05 +08:00
Fangrui Song
0c04c27e59 Add cache.{hierarchicalPath,retainInMemory}
cache.hierarchicalPath: store cache files as $directory/a/b/c.cc.blob to
work around NAME_MAX limitation.

cache.retainInMemory: after this number of loads, keep a copy of file
index in memory. If set to 1, it avoids cache corruption if the index
file is changed after the initial load, which may happen if several
language clients open the same project and share the same cache
directory.

Also rename cacheDirectory cacheFormat to cache.{directory,format}
2019-02-21 23:46:20 +08:00
Leszek Swirski
633d8936a8 Use DiagnosticRelatedInformation if client supports publishDiagnostics.relatedInformation (#276)
In clients that support DiagnosticRelatedInformation, display
clang notes as these nested diagnostics rather than appending
them to the parent diagnostic's message. Behaviour for clients
that don't support related information should be unchanged.
2019-02-21 02:23:21 +01:00
Fangrui Song
66e9cbd9a6 indexer: change Pos computation from byte offset to UTF-8 encoded code point offset 2019-02-16 17:23:47 +08:00
Fangrui Song
3bf921b3bd Add initialization option capabilities.* and index.maxInitializerLines
indexer.cc: use index.maxInitializerLines instead of kInitializerMaxLines

messages/initialize.cc: some ServerCapabilities are toggable:

documentOnTypeFormattingProvider.firstTriggerCharacter
foldingRangeProvider
workspace.workspaceFolders.supported
2019-02-10 18:17:07 +08:00
Fangrui Song
aaa97fe8df GetFallback: append clang.extraArgs
When compile_commands.json is absent, GetFallback is called to get
default clang command line when there is no .ccls or .ccls is empty.
2019-02-10 11:58:18 +08:00
Fangrui Song
03f91f0681 Compute CompletionItemKind from Declaration instead of CursorKind 2019-02-02 14:14:23 +08:00
Riatre Foo
2db67f6edb Fix is_local for vars with non-auto storage period 2018-10-15 23:25:46 +08:00
Riatre Foo
cd0f204349 textDocument/signatureHelp: enable documentation 2018-10-14 07:58:08 +08:00
Fangrui Song
716bc01322 Log {Request,Notification}Message, and timestamp change due to dependency 2019-01-29 15:47:03 +08:00
Riatre Foo
84f7d5081f Fix completion result sorting in VSCode (#210)
Fix #207
2019-01-30 23:21:40 +08:00
Fangrui Song
343fa74dc1 Implement initialization option compilationDatabaseCommand on Windows 2019-01-21 12:15:28 +08:00
Fangrui Song
c6d56519e3 Drop support for clang 6 2019-01-21 10:44:44 +08:00
Fangrui Song
f496580081 Add -log-file=stderr and make it default
Change -log-file-append to a boolean flag
2019-01-21 10:20:07 +08:00
Fangrui Song
c592f95be0 completion: if preamble size changes, rebuild it
Fix #190

If a new header is added, the preamble size changes. Language clients may cache completion results, thus we rebuild preamble to avoid inaccurate results.
2019-01-13 18:33:18 +08:00
Fangrui Song
f99cf50456 textDocument/didOpen: index related files when a header is opened
Fix #180

index.initialBlacklist: ["."] can inhibit initial indexing (useful for larger code bases).
Opened files are still indexed, though.
This heuristic allows related files (a/foo.c a/b/foo.cc) to be indexed when a header (foo.h) is opened.
2019-11-09 20:09:13 -08:00
Fangrui Song
8835a555f8 Delay requests if the document has not not indexed (#176)
This fixes a plethora of "not indexed" errors when the document has not been indexed.

* Message handler throws NotIndexed if not overdue
* The message is put into backlog and tagged with backlog_path
* path2backlog[path] tracks backlog associated with document `path`
* The backlog is cleared when the index is merged
* backlog[0] is forced to run if it becomes overdue
2019-11-09 20:09:13 -08:00
Fangrui Song
dd74d03cfc Adjust FrontendOpts.Inputs[0] for inferred files 2019-11-09 20:09:13 -08:00
Fangrui Song
52e0289245 Handle file deletion and register workspace/didChangeWatchedFiles
* In the "initialized" callback, send client/registerCapability with DidChangeWatchedFilesRegistrationOptions
* In workspace/didChangeWatchedFiles callback, call pipeline::Index
* In pipeline::Index, add a `deleted` status
2019-11-09 20:09:13 -08:00
Fangrui Song
ab48179946 Make cacheDirectory related to project root; delete Timer 2019-11-09 20:09:13 -08:00
Fangrui Song
45ac75fce3 completion: ignore CXXDeductionGuide
Fix #173
2019-11-09 20:09:13 -08:00
Fangrui Song
c085e07b19 Extend .ccls
* Add %h for C header files (the suffix .h is considered a C header, not a C++ header)
* Add %hpp for C++ header files
* If .ccls exists, it provides full command line for files not specified by compile_commands.json (before, compile_commands.json was ignored)
* If the first line of .ccls is %compile_commands.json, it appends flags to compile_commands.json "arguments", instead of overriding.
  Files not specified by compile_commands.json will not be added to folder.entries, but their command line can be inferred from other files.

Also fix `#include <` completion of -I flags for clang < 8
2019-11-09 20:09:13 -08:00
Fangrui Song
3edda5cf76 Make -v=1 work and log cflags for SemaManager session and Indexer 2019-11-09 20:09:13 -08:00
Fangrui Song
6e8a45b25e Add strict to FuzzyMatcher::Match
In completion, underscore prefixed builtin macros may be annoying when the first type character is not an underscore.

When `strict` is true, `Match` enforces the first characters should be loosely of the same category.
2019-11-09 20:09:13 -08:00
Fangrui Song
836caba19b ParameterInformation: use label: [number, number]
Don't bother checking signatureHelp.signatureInformationparameterInformation.labelOffsetSupport
2019-11-09 20:09:13 -08:00
Fangrui Song
49ae9e8912 Support textDocument/declaration & LocationLink
textDocument/{declaration,definition,typeDefinition} return either LocationLink[] or Location[]
Add an initialization option client.linkSupport . When it is false, ccls will return Location[] disregarding client's linkSupport.
`struct LocationLink` does not include originSelectionRange as it is wasteful.
2019-11-09 20:09:13 -08:00
Fangrui Song
e3133bea90 cmake_minimum_required 3.8; clean up 2019-11-09 20:09:13 -08:00
Fangrui Song
20e0beb9f3 Rendezvous after receiving "exit" notification (#159) 2019-11-09 20:09:13 -08:00
Fangrui Song
c06c2ca324 Support multiple -init=
Initialization options are applied (deserialized to the same object) in the following order:

* "initializationOptions" from client
* first -init=
* second -init=
* ...

Scalar options will be overridden but arrays will get concatenated, e.g.

ccls -log-file=/dev/stderr -index . -init='{"clang":{"extraArgs":["-DA"]}}' -init='{"clang":{"extraArgs":["-DB"]}}'

results in clang.extraArgs: ["-DA", "-DB"]
2019-11-09 20:09:13 -08:00
Leszek Swirski
25c8928121 Spin IncludeComplete's destructor until scanning completes (#147) 2019-11-09 20:09:13 -08:00
Fangrui Song
c941ca1bcd query: fix UpdateUses when a new entity is seen; simplify {DeclRef,Use,Usr}Update
Thanks to Leszek Swirski
2019-11-09 20:09:13 -08:00
Fangrui Song
a47fb42e30 Refactor serializer
Delete virtual bases Reader & Writer
Delete unused MAKE_REFLECT_STRUCT_WRITER_AS_ARRAY
Merge serializers/{json,binary}.hh into serializer.{hh,cc}
MAKE_REFLECT_STRUCT => REFLECT_STRUCT
MAKE_REFLECT_TYPE_PROXY => REFLECT_UNDERLYING
2019-11-09 20:09:13 -08:00
Fangrui Song
a599aef482 Add ReplyOnce::NotReady and error if didOpen is not seen
Use IgnoringDiagConsumer to override default TextDiagnosticPrinter
2019-11-09 20:09:13 -08:00
Fangrui Song
9ad2450009 Refactor WorkingFiles and CompletionManager
* WorkingFiles::files : vector -> unordered_map
* Add timestamp to WorkingFile

* Rename "comp-preload" thread to "preamble"
* Rename CompletionManager to SemaManager as it is used by "diag" "comp" "preamble"
* Rename clang_complete.* to sema_manager.*
* Merge SemaManager::{preloads,sessions}
* Add initialization option session.maxNum
* In DiagnosticMain, if an included file was modified, cancel the DiagTask and create a PreambleTask instead. The task sets `from_diag` so as to trigger immediate DiagTask after the preamble is built.
2019-11-09 20:09:13 -08:00
Fangrui Song
b9369e055a completion: use Text for Macro{Instantiation,Definition} 2019-11-09 20:09:13 -08:00
Fangrui Song
c6c234725a Fix ComputeGuessScore and delete dead code
Thanks to CXuesong
2019-11-09 20:09:13 -08:00
Fangrui Song
65d856cf8a Merge maybe.hh into utils.hh 2019-11-09 20:09:13 -08:00
Fangrui Song
880c515d64 Merge query.hh and query_util.hh 2019-11-09 20:09:13 -08:00
Fangrui Song
d6dd932e6d Refactor Matcher to use pimpl and merge match.hh into utils.hh 2019-11-09 20:09:13 -08:00
Fangrui Song
38e87a0729 Make EmptyParam empty & rewrite LruCache 2019-11-09 20:09:13 -08:00
Fangrui Song
9603a73421 constexpr std::string_view -> const std::string_view
This works around gcc 7.2/clang rC347417 which have a bad interaction with libstdc++'s implementation of P0426
constexpr std::string_view also emits a string_view object in .rodata that cannot be optimized out by clang (which means larger object file size)

So use good old const.
2019-11-09 20:09:13 -08:00
Fangrui Song
7f8f68c0b2 codeAction: use codeActionProvider: CodeActionOptions and respect CodeActionParams::range 2019-11-09 20:09:13 -08:00
Fangrui Song
19d38bc1d2 Make DocumentLink::range narrower
Thanks to Riatre #135
2019-11-09 20:09:13 -08:00
Fangrui Song
0f0c328a91 completion: delete insertText; don't set filterText if it is the same as label
It decreases Content-Length: from 32K to 25K for the following case:

 #include <bits/stdc++.h>
int main() { std::| }

Also

* make results deterministic when completion text is empty
* sort by newText, label, filterText
2019-11-09 20:09:13 -08:00
Fangrui Song
98be09cc2e serializer: make visitor/vis value/v consistent 2019-11-09 20:09:13 -08:00
Fangrui Song
741d8f2130 Refactor ReplyOnce; error if InitializeParams.rootUri is null 2019-11-09 20:09:13 -08:00
Fangrui Song
8f442c6c35 indexer: handle DecltypeType and empty main file; diag: -Wno-unused-function for headers
Don't replace name with qualified name in Cls::*name
2019-11-09 20:09:13 -08:00
Fangrui Song
e27a5eaff9 .ccls: add %objective-c %objective-cpp
Also allow multiple directives on a line, e.g. %c %cpp -DFOO
2019-11-09 20:09:13 -08:00
Fangrui Song
46d3f075dc Use clang::isIdentifierBody and clean up utils/working_files 2019-11-09 20:09:13 -08:00
Fangrui Song
95bba3ed15 hierarchicalDocumentSymbol: support SymbolKind::Function declaration and uniquify by range
Also ensure selectionRange is a subrange of range, otherwise VSCode won't show the item.
Use detailed_name for 'detail'
2019-11-09 20:09:13 -08:00
Fangrui Song
985f5ec4d3 Use SM.isWrittenInMainFile; suppress -Werror in preamble
SM.isWrittenInMainFile is to work around preamble bug: spurious err_pp_unterminated_conditional with circular #include
2019-11-09 20:09:13 -08:00