mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-24 08:35:08 +00:00
Reduce MAKE_REFLECT_STRUCT in lsp.hh
Position -> Pos; lsPosition -> Position
This commit is contained in:
parent
11ba6b64ff
commit
e0e00cb48a
@ -508,17 +508,17 @@ void *DiagnosticMain(void *manager_) {
|
|||||||
case DiagnosticsEngine::Ignored:
|
case DiagnosticsEngine::Ignored:
|
||||||
// llvm_unreachable
|
// llvm_unreachable
|
||||||
case DiagnosticsEngine::Remark:
|
case DiagnosticsEngine::Remark:
|
||||||
ret.severity = DiagnosticSeverity::Hint;
|
ret.severity = 4;
|
||||||
break;
|
break;
|
||||||
case DiagnosticsEngine::Note:
|
case DiagnosticsEngine::Note:
|
||||||
ret.severity = DiagnosticSeverity::Information;
|
ret.severity = 3;
|
||||||
break;
|
break;
|
||||||
case DiagnosticsEngine::Warning:
|
case DiagnosticsEngine::Warning:
|
||||||
ret.severity = DiagnosticSeverity::Warning;
|
ret.severity = 2;
|
||||||
break;
|
break;
|
||||||
case DiagnosticsEngine::Error:
|
case DiagnosticsEngine::Error:
|
||||||
case DiagnosticsEngine::Fatal:
|
case DiagnosticsEngine::Fatal:
|
||||||
ret.severity = DiagnosticSeverity::Error;
|
ret.severity = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ret.code = d.category;
|
ret.code = d.category;
|
||||||
|
@ -87,7 +87,7 @@ struct CompletionManager {
|
|||||||
struct CompletionRequest {
|
struct CompletionRequest {
|
||||||
CompletionRequest(const RequestId &id,
|
CompletionRequest(const RequestId &id,
|
||||||
const TextDocumentIdentifier &document,
|
const TextDocumentIdentifier &document,
|
||||||
const lsPosition &position,
|
const Position &position,
|
||||||
std::unique_ptr<clang::CodeCompleteConsumer> Consumer,
|
std::unique_ptr<clang::CodeCompleteConsumer> Consumer,
|
||||||
clang::CodeCompleteOptions CCOpts,
|
clang::CodeCompleteOptions CCOpts,
|
||||||
const OnComplete &on_complete)
|
const OnComplete &on_complete)
|
||||||
@ -97,7 +97,7 @@ struct CompletionManager {
|
|||||||
|
|
||||||
RequestId id;
|
RequestId id;
|
||||||
TextDocumentIdentifier document;
|
TextDocumentIdentifier document;
|
||||||
lsPosition position;
|
Position position;
|
||||||
std::unique_ptr<clang::CodeCompleteConsumer> Consumer;
|
std::unique_ptr<clang::CodeCompleteConsumer> Consumer;
|
||||||
clang::CodeCompleteOptions CCOpts;
|
clang::CodeCompleteOptions CCOpts;
|
||||||
OnComplete on_complete;
|
OnComplete on_complete;
|
||||||
@ -177,7 +177,7 @@ template <typename T>
|
|||||||
struct CompleteConsumerCache {
|
struct CompleteConsumerCache {
|
||||||
// NOTE: Make sure to access these variables under |WithLock|.
|
// NOTE: Make sure to access these variables under |WithLock|.
|
||||||
std::optional<std::string> path;
|
std::optional<std::string> path;
|
||||||
std::optional<lsPosition> position;
|
std::optional<Position> position;
|
||||||
T result;
|
T result;
|
||||||
|
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
@ -186,7 +186,7 @@ struct CompleteConsumerCache {
|
|||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
action();
|
action();
|
||||||
}
|
}
|
||||||
bool IsCacheValid(const std::string path, lsPosition position) {
|
bool IsCacheValid(const std::string path, Position position) {
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
return this->path == path && this->position == position;
|
return this->path == path && this->position == position;
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,8 @@ std::string PathFromFileEntry(const FileEntry &file) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Position Decomposed2LineAndCol(const SourceManager &SM,
|
static Pos Decomposed2LineAndCol(const SourceManager &SM,
|
||||||
std::pair<FileID, unsigned> I) {
|
std::pair<FileID, unsigned> I) {
|
||||||
int l = SM.getLineNumber(I.first, I.second) - 1,
|
int l = SM.getLineNumber(I.first, I.second) - 1,
|
||||||
c = SM.getColumnNumber(I.first, I.second) - 1;
|
c = SM.getColumnNumber(I.first, I.second) - 1;
|
||||||
return {(int16_t)std::min(l, INT16_MAX), (int16_t)std::min(c, INT16_MAX)};
|
return {(int16_t)std::min(l, INT16_MAX), (int16_t)std::min(c, INT16_MAX)};
|
||||||
|
@ -43,7 +43,32 @@ template <> struct hash<llvm::sys::fs::UniqueID> {
|
|||||||
|
|
||||||
namespace ccls {
|
namespace ccls {
|
||||||
using Usr = uint64_t;
|
using Usr = uint64_t;
|
||||||
enum class LanguageId;
|
|
||||||
|
// The order matters. In FindSymbolsAtLocation, we want Var/Func ordered in
|
||||||
|
// front of others.
|
||||||
|
enum class Kind : uint8_t { Invalid, File, Type, Func, Var };
|
||||||
|
MAKE_REFLECT_TYPE_PROXY(Kind);
|
||||||
|
|
||||||
|
enum class Role : uint16_t {
|
||||||
|
None = 0,
|
||||||
|
Declaration = 1 << 0,
|
||||||
|
Definition = 1 << 1,
|
||||||
|
Reference = 1 << 2,
|
||||||
|
Read = 1 << 3,
|
||||||
|
Write = 1 << 4,
|
||||||
|
Call = 1 << 5,
|
||||||
|
Dynamic = 1 << 6,
|
||||||
|
Address = 1 << 7,
|
||||||
|
Implicit = 1 << 8,
|
||||||
|
All = (1 << 9) - 1,
|
||||||
|
};
|
||||||
|
MAKE_REFLECT_TYPE_PROXY(Role);
|
||||||
|
inline uint16_t operator&(Role lhs, Role rhs) {
|
||||||
|
return uint16_t(lhs) & uint16_t(rhs);
|
||||||
|
}
|
||||||
|
inline Role operator|(Role lhs, Role rhs) {
|
||||||
|
return Role(uint16_t(lhs) | uint16_t(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
struct SymbolIdx {
|
struct SymbolIdx {
|
||||||
Usr usr;
|
Usr usr;
|
||||||
@ -56,7 +81,6 @@ struct SymbolIdx {
|
|||||||
return usr != o.usr ? usr < o.usr : kind < o.kind;
|
return usr != o.usr ? usr < o.usr : kind < o.kind;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(SymbolIdx, usr, kind);
|
|
||||||
|
|
||||||
// |id,kind| refer to the referenced entity.
|
// |id,kind| refer to the referenced entity.
|
||||||
struct SymbolRef {
|
struct SymbolRef {
|
||||||
|
@ -136,11 +136,7 @@ std::string DocumentUri::GetPath() const {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string lsPosition::ToString() const {
|
std::string Position::ToString() const {
|
||||||
return std::to_string(line) + ":" + std::to_string(character);
|
return std::to_string(line) + ":" + std::to_string(character);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextEdit::operator==(const TextEdit &that) {
|
|
||||||
return range == that.range && newText == that.newText;
|
|
||||||
}
|
|
||||||
} // namespace ccls
|
} // namespace ccls
|
||||||
|
116
src/lsp.hh
116
src/lsp.hh
@ -60,7 +60,6 @@ enum class ErrorCode {
|
|||||||
// Defined by the protocol.
|
// Defined by the protocol.
|
||||||
RequestCancelled = -32800,
|
RequestCancelled = -32800,
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_TYPE_PROXY(ErrorCode);
|
|
||||||
|
|
||||||
struct ResponseError {
|
struct ResponseError {
|
||||||
// A number indicating the error type that occurred.
|
// A number indicating the error type that occurred.
|
||||||
@ -73,19 +72,10 @@ struct ResponseError {
|
|||||||
// information about the error. Can be omitted.
|
// information about the error. Can be omitted.
|
||||||
// std::optional<D> data;
|
// std::optional<D> data;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(ResponseError, code, message);
|
|
||||||
|
|
||||||
constexpr char ccls_xref[] = "ccls.xref";
|
constexpr char ccls_xref[] = "ccls.xref";
|
||||||
constexpr char window_showMessage[] = "window/showMessage";
|
constexpr char window_showMessage[] = "window/showMessage";
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
////////////////////////////// PRIMITIVE TYPES //////////////////////////////
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
struct DocumentUri {
|
struct DocumentUri {
|
||||||
static DocumentUri FromPath(const std::string &path);
|
static DocumentUri FromPath(const std::string &path);
|
||||||
|
|
||||||
@ -102,22 +92,21 @@ void Reflect(TVisitor &visitor, DocumentUri &value) {
|
|||||||
Reflect(visitor, value.raw_uri);
|
Reflect(visitor, value.raw_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct lsPosition {
|
struct Position {
|
||||||
int line = 0;
|
int line = 0;
|
||||||
int character = 0;
|
int character = 0;
|
||||||
bool operator==(const lsPosition &o) const {
|
bool operator==(const Position &o) const {
|
||||||
return line == o.line && character == o.character;
|
return line == o.line && character == o.character;
|
||||||
}
|
}
|
||||||
bool operator<(const lsPosition &o) const {
|
bool operator<(const Position &o) const {
|
||||||
return line != o.line ? line < o.line : character < o.character;
|
return line != o.line ? line < o.line : character < o.character;
|
||||||
}
|
}
|
||||||
std::string ToString() const;
|
std::string ToString() const;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(lsPosition, line, character);
|
|
||||||
|
|
||||||
struct lsRange {
|
struct lsRange {
|
||||||
lsPosition start;
|
Position start;
|
||||||
lsPosition end;
|
Position end;
|
||||||
bool operator==(const lsRange &o) const {
|
bool operator==(const lsRange &o) const {
|
||||||
return start == o.start && end == o.end;
|
return start == o.start && end == o.end;
|
||||||
}
|
}
|
||||||
@ -125,7 +114,6 @@ struct lsRange {
|
|||||||
return !(start == o.start) ? start < o.start : end < o.end;
|
return !(start == o.start) ? start < o.start : end < o.end;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(lsRange, start, end);
|
|
||||||
|
|
||||||
struct Location {
|
struct Location {
|
||||||
DocumentUri uri;
|
DocumentUri uri;
|
||||||
@ -138,7 +126,6 @@ struct Location {
|
|||||||
: range < o.range;
|
: range < o.range;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(Location, uri, range);
|
|
||||||
|
|
||||||
enum class SymbolKind : uint8_t {
|
enum class SymbolKind : uint8_t {
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
@ -181,7 +168,6 @@ enum class SymbolKind : uint8_t {
|
|||||||
StaticMethod = 254,
|
StaticMethod = 254,
|
||||||
Macro = 255,
|
Macro = 255,
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_TYPE_PROXY(SymbolKind);
|
|
||||||
|
|
||||||
struct SymbolInformation {
|
struct SymbolInformation {
|
||||||
std::string_view name;
|
std::string_view name;
|
||||||
@ -193,57 +179,24 @@ struct SymbolInformation {
|
|||||||
struct TextDocumentIdentifier {
|
struct TextDocumentIdentifier {
|
||||||
DocumentUri uri;
|
DocumentUri uri;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(TextDocumentIdentifier, uri);
|
|
||||||
|
|
||||||
struct VersionedTextDocumentIdentifier {
|
struct VersionedTextDocumentIdentifier {
|
||||||
DocumentUri uri;
|
DocumentUri uri;
|
||||||
// The version number of this document. number | null
|
// The version number of this document. number | null
|
||||||
std::optional<int> version;
|
std::optional<int> version;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(VersionedTextDocumentIdentifier, uri, version);
|
|
||||||
|
|
||||||
struct TextEdit {
|
struct TextEdit {
|
||||||
// The range of the text document to be manipulated. To insert
|
|
||||||
// text into a document create a range where start === end.
|
|
||||||
lsRange range;
|
lsRange range;
|
||||||
|
|
||||||
// The string to be inserted. For delete operations use an
|
|
||||||
// empty string.
|
|
||||||
std::string newText;
|
std::string newText;
|
||||||
|
|
||||||
bool operator==(const TextEdit &that);
|
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(TextEdit, range, newText);
|
|
||||||
|
|
||||||
struct TextDocumentItem {
|
struct TextDocumentItem {
|
||||||
// The text document's URI.
|
|
||||||
DocumentUri uri;
|
DocumentUri uri;
|
||||||
|
|
||||||
// The text document's language identifier.
|
|
||||||
std::string languageId;
|
std::string languageId;
|
||||||
|
|
||||||
// The version number of this document (it will strictly increase after each
|
|
||||||
// change, including undo/redo).
|
|
||||||
int version;
|
int version;
|
||||||
|
|
||||||
// The content of the opened text document.
|
|
||||||
std::string text;
|
std::string text;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(TextDocumentItem, uri, languageId, version, text);
|
|
||||||
|
|
||||||
struct TextDocumentEdit {
|
|
||||||
// The text document to change.
|
|
||||||
VersionedTextDocumentIdentifier textDocument;
|
|
||||||
|
|
||||||
// The edits to be applied.
|
|
||||||
std::vector<TextEdit> edits;
|
|
||||||
};
|
|
||||||
MAKE_REFLECT_STRUCT(TextDocumentEdit, textDocument, edits);
|
|
||||||
|
|
||||||
struct WorkspaceEdit {
|
|
||||||
std::vector<TextDocumentEdit> documentChanges;
|
|
||||||
};
|
|
||||||
MAKE_REFLECT_STRUCT(WorkspaceEdit, documentChanges);
|
|
||||||
|
|
||||||
struct TextDocumentContentChangeEvent {
|
struct TextDocumentContentChangeEvent {
|
||||||
// The range of the document that changed.
|
// The range of the document that changed.
|
||||||
@ -263,84 +216,27 @@ struct WorkspaceFolder {
|
|||||||
DocumentUri uri;
|
DocumentUri uri;
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(WorkspaceFolder, uri, name);
|
|
||||||
|
|
||||||
// Show a message to the user.
|
|
||||||
enum class MessageType : int { Error = 1, Warning = 2, Info = 3, Log = 4 };
|
enum class MessageType : int { Error = 1, Warning = 2, Info = 3, Log = 4 };
|
||||||
MAKE_REFLECT_TYPE_PROXY(MessageType)
|
MAKE_REFLECT_TYPE_PROXY(MessageType)
|
||||||
|
|
||||||
enum class DiagnosticSeverity {
|
|
||||||
// Reports an error.
|
|
||||||
Error = 1,
|
|
||||||
// Reports a warning.
|
|
||||||
Warning = 2,
|
|
||||||
// Reports an information.
|
|
||||||
Information = 3,
|
|
||||||
// Reports a hint.
|
|
||||||
Hint = 4
|
|
||||||
};
|
|
||||||
MAKE_REFLECT_TYPE_PROXY(DiagnosticSeverity);
|
|
||||||
|
|
||||||
struct Diagnostic {
|
struct Diagnostic {
|
||||||
// The range at which the message applies.
|
|
||||||
lsRange range;
|
lsRange range;
|
||||||
|
int severity = 0;
|
||||||
// The diagnostic's severity. Can be omitted. If omitted it is up to the
|
|
||||||
// client to interpret diagnostics as error, warning, info or hint.
|
|
||||||
std::optional<DiagnosticSeverity> severity;
|
|
||||||
|
|
||||||
// The diagnostic's code. Can be omitted.
|
|
||||||
int code = 0;
|
int code = 0;
|
||||||
|
|
||||||
// A human-readable string describing the source of this
|
|
||||||
// diagnostic, e.g. 'typescript' or 'super lint'.
|
|
||||||
std::string source = "ccls";
|
std::string source = "ccls";
|
||||||
|
|
||||||
// The diagnostic's message.
|
|
||||||
std::string message;
|
std::string message;
|
||||||
|
|
||||||
// Non-serialized set of fixits.
|
|
||||||
std::vector<TextEdit> fixits_;
|
std::vector<TextEdit> fixits_;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(Diagnostic, range, severity, source, message);
|
|
||||||
|
|
||||||
struct ShowMessageParam {
|
struct ShowMessageParam {
|
||||||
MessageType type = MessageType::Error;
|
MessageType type = MessageType::Error;
|
||||||
std::string message;
|
std::string message;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(ShowMessageParam, type, message);
|
|
||||||
|
|
||||||
// Used to identify the language at a file level. The ordering is important, as
|
// Used to identify the language at a file level. The ordering is important, as
|
||||||
// a file previously identified as `C`, will be changed to `Cpp` if it
|
// a file previously identified as `C`, will be changed to `Cpp` if it
|
||||||
// encounters a c++ declaration.
|
// encounters a c++ declaration.
|
||||||
enum class LanguageId { Unknown = -1, C = 0, Cpp = 1, ObjC = 2, ObjCpp = 3 };
|
enum class LanguageId { Unknown = -1, C = 0, Cpp = 1, ObjC = 2, ObjCpp = 3 };
|
||||||
MAKE_REFLECT_TYPE_PROXY(LanguageId);
|
|
||||||
|
|
||||||
// The order matters. In FindSymbolsAtLocation, we want Var/Func ordered in
|
|
||||||
// front of others.
|
|
||||||
enum class Kind : uint8_t { Invalid, File, Type, Func, Var };
|
|
||||||
MAKE_REFLECT_TYPE_PROXY(Kind);
|
|
||||||
|
|
||||||
enum class Role : uint16_t {
|
|
||||||
None = 0,
|
|
||||||
Declaration = 1 << 0,
|
|
||||||
Definition = 1 << 1,
|
|
||||||
Reference = 1 << 2,
|
|
||||||
Read = 1 << 3,
|
|
||||||
Write = 1 << 4,
|
|
||||||
Call = 1 << 5,
|
|
||||||
Dynamic = 1 << 6,
|
|
||||||
Address = 1 << 7,
|
|
||||||
Implicit = 1 << 8,
|
|
||||||
All = (1 << 9) - 1,
|
|
||||||
};
|
|
||||||
MAKE_REFLECT_TYPE_PROXY(Role);
|
|
||||||
|
|
||||||
inline uint16_t operator&(Role lhs, Role rhs) {
|
|
||||||
return uint16_t(lhs) & uint16_t(rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Role operator|(Role lhs, Role rhs) {
|
|
||||||
return Role(uint16_t(lhs) | uint16_t(rhs));
|
|
||||||
}
|
|
||||||
} // namespace ccls
|
} // namespace ccls
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
|
|
||||||
#include "match.hh"
|
#include "match.hh"
|
||||||
|
|
||||||
#include "lsp.hh"
|
#include "message_handler.hh"
|
||||||
#include "pipeline.hh"
|
#include "pipeline.hh"
|
||||||
|
|
||||||
namespace ccls {
|
namespace ccls {
|
||||||
|
@ -30,6 +30,8 @@ using namespace clang;
|
|||||||
MAKE_HASHABLE(ccls::SymbolIdx, t.usr, t.kind);
|
MAKE_HASHABLE(ccls::SymbolIdx, t.usr, t.kind);
|
||||||
|
|
||||||
namespace ccls {
|
namespace ccls {
|
||||||
|
MAKE_REFLECT_STRUCT(CodeActionParam::Context, diagnostics);
|
||||||
|
MAKE_REFLECT_STRUCT(CodeActionParam, textDocument, range, context);
|
||||||
MAKE_REFLECT_STRUCT(EmptyParam, placeholder);
|
MAKE_REFLECT_STRUCT(EmptyParam, placeholder);
|
||||||
MAKE_REFLECT_STRUCT(TextDocumentParam, textDocument);
|
MAKE_REFLECT_STRUCT(TextDocumentParam, textDocument);
|
||||||
MAKE_REFLECT_STRUCT(DidOpenTextDocumentParam, textDocument);
|
MAKE_REFLECT_STRUCT(DidOpenTextDocumentParam, textDocument);
|
||||||
@ -38,10 +40,6 @@ MAKE_REFLECT_STRUCT(TextDocumentDidChangeParam, textDocument, contentChanges);
|
|||||||
MAKE_REFLECT_STRUCT(TextDocumentPositionParam, textDocument, position);
|
MAKE_REFLECT_STRUCT(TextDocumentPositionParam, textDocument, position);
|
||||||
MAKE_REFLECT_STRUCT(RenameParam, textDocument, position, newName);
|
MAKE_REFLECT_STRUCT(RenameParam, textDocument, position, newName);
|
||||||
|
|
||||||
// code*
|
|
||||||
MAKE_REFLECT_STRUCT(CodeActionParam::Context, diagnostics);
|
|
||||||
MAKE_REFLECT_STRUCT(CodeActionParam, textDocument, range, context);
|
|
||||||
|
|
||||||
// completion
|
// completion
|
||||||
MAKE_REFLECT_TYPE_PROXY(CompletionTriggerKind);
|
MAKE_REFLECT_TYPE_PROXY(CompletionTriggerKind);
|
||||||
MAKE_REFLECT_STRUCT(CompletionContext, triggerKind, triggerCharacter);
|
MAKE_REFLECT_STRUCT(CompletionContext, triggerKind, triggerCharacter);
|
||||||
@ -74,24 +72,23 @@ struct CclsSemanticHighlightSymbol {
|
|||||||
std::vector<lsRange> lsRanges;
|
std::vector<lsRange> lsRanges;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CclsSemanticHighlightParams {
|
struct CclsSemanticHighlight {
|
||||||
DocumentUri uri;
|
DocumentUri uri;
|
||||||
std::vector<CclsSemanticHighlightSymbol> symbols;
|
std::vector<CclsSemanticHighlightSymbol> symbols;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(CclsSemanticHighlightSymbol, id, parentKind, kind, storage,
|
MAKE_REFLECT_STRUCT(CclsSemanticHighlightSymbol, id, parentKind, kind, storage,
|
||||||
ranges, lsRanges);
|
ranges, lsRanges);
|
||||||
MAKE_REFLECT_STRUCT(CclsSemanticHighlightParams, uri, symbols);
|
MAKE_REFLECT_STRUCT(CclsSemanticHighlight, uri, symbols);
|
||||||
|
|
||||||
struct CclsSetSkippedRangesParams {
|
struct CclsSetSkippedRanges {
|
||||||
DocumentUri uri;
|
DocumentUri uri;
|
||||||
std::vector<lsRange> skippedRanges;
|
std::vector<lsRange> skippedRanges;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(CclsSetSkippedRangesParams, uri, skippedRanges);
|
MAKE_REFLECT_STRUCT(CclsSetSkippedRanges, uri, skippedRanges);
|
||||||
|
|
||||||
|
|
||||||
struct ScanLineEvent {
|
struct ScanLineEvent {
|
||||||
lsPosition pos;
|
Position pos;
|
||||||
lsPosition end_pos; // Second key when there is a tie for insertion events.
|
Position end_pos; // Second key when there is a tie for insertion events.
|
||||||
int id;
|
int id;
|
||||||
CclsSemanticHighlightSymbol *symbol;
|
CclsSemanticHighlightSymbol *symbol;
|
||||||
bool operator<(const ScanLineEvent &other) const {
|
bool operator<(const ScanLineEvent &other) const {
|
||||||
@ -273,7 +270,7 @@ QueryFile *MessageHandler::FindFile(ReplyOnce &reply,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EmitSkippedRanges(WorkingFile *wfile, QueryFile &file) {
|
void EmitSkippedRanges(WorkingFile *wfile, QueryFile &file) {
|
||||||
CclsSetSkippedRangesParams params;
|
CclsSetSkippedRanges params;
|
||||||
params.uri = DocumentUri::FromPath(wfile->filename);
|
params.uri = DocumentUri::FromPath(wfile->filename);
|
||||||
for (Range skipped : file.def->skipped_ranges)
|
for (Range skipped : file.def->skipped_ranges)
|
||||||
if (auto ls_skipped = GetLsRange(wfile, skipped))
|
if (auto ls_skipped = GetLsRange(wfile, skipped))
|
||||||
@ -365,8 +362,7 @@ void EmitSemanticHighlight(DB *db, WorkingFile *wfile, QueryFile &file) {
|
|||||||
continue; // applies to for loop
|
continue; // applies to for loop
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<lsRange> loc = GetLsRange(wfile, sym.range);
|
if (std::optional<lsRange> loc = GetLsRange(wfile, sym.range)) {
|
||||||
if (loc) {
|
|
||||||
auto it = grouped_symbols.find(sym);
|
auto it = grouped_symbols.find(sym);
|
||||||
if (it != grouped_symbols.end()) {
|
if (it != grouped_symbols.end()) {
|
||||||
it->second.lsRanges.push_back(*loc);
|
it->second.lsRanges.push_back(*loc);
|
||||||
@ -421,7 +417,7 @@ void EmitSemanticHighlight(DB *db, WorkingFile *wfile, QueryFile &file) {
|
|||||||
deleted[~events[i].id] = 1;
|
deleted[~events[i].id] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CclsSemanticHighlightParams params;
|
CclsSemanticHighlight params;
|
||||||
params.uri = DocumentUri::FromPath(wfile->filename);
|
params.uri = DocumentUri::FromPath(wfile->filename);
|
||||||
// Transform lsRange into pair<int, int> (offset pairs)
|
// Transform lsRange into pair<int, int> (offset pairs)
|
||||||
if (!g_config->highlight.lsRanges) {
|
if (!g_config->highlight.lsRanges) {
|
||||||
|
@ -36,28 +36,6 @@ void Reply(RequestId id, const std::function<void(Writer &)> &fn);
|
|||||||
void ReplyError(RequestId id, const std::function<void(Writer &)> &fn);
|
void ReplyError(RequestId id, const std::function<void(Writer &)> &fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EmptyParam {
|
|
||||||
bool placeholder;
|
|
||||||
};
|
|
||||||
struct TextDocumentParam {
|
|
||||||
TextDocumentIdentifier textDocument;
|
|
||||||
};
|
|
||||||
struct DidOpenTextDocumentParam {
|
|
||||||
TextDocumentItem textDocument;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TextDocumentPositionParam {
|
|
||||||
TextDocumentIdentifier textDocument;
|
|
||||||
lsPosition position;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct RenameParam {
|
|
||||||
TextDocumentIdentifier textDocument;
|
|
||||||
lsPosition position;
|
|
||||||
std::string newName;
|
|
||||||
};
|
|
||||||
|
|
||||||
// code*
|
|
||||||
struct CodeActionParam {
|
struct CodeActionParam {
|
||||||
TextDocumentIdentifier textDocument;
|
TextDocumentIdentifier textDocument;
|
||||||
lsRange range;
|
lsRange range;
|
||||||
@ -65,6 +43,33 @@ struct CodeActionParam {
|
|||||||
std::vector<Diagnostic> diagnostics;
|
std::vector<Diagnostic> diagnostics;
|
||||||
} context;
|
} context;
|
||||||
};
|
};
|
||||||
|
struct EmptyParam {
|
||||||
|
bool placeholder;
|
||||||
|
};
|
||||||
|
struct DidOpenTextDocumentParam {
|
||||||
|
TextDocumentItem textDocument;
|
||||||
|
};
|
||||||
|
struct RenameParam {
|
||||||
|
TextDocumentIdentifier textDocument;
|
||||||
|
Position position;
|
||||||
|
std::string newName;
|
||||||
|
};
|
||||||
|
struct TextDocumentParam {
|
||||||
|
TextDocumentIdentifier textDocument;
|
||||||
|
};
|
||||||
|
struct TextDocumentPositionParam {
|
||||||
|
TextDocumentIdentifier textDocument;
|
||||||
|
Position position;
|
||||||
|
};
|
||||||
|
struct TextDocumentEdit {
|
||||||
|
VersionedTextDocumentIdentifier textDocument;
|
||||||
|
std::vector<TextEdit> edits;
|
||||||
|
};
|
||||||
|
MAKE_REFLECT_STRUCT(TextDocumentEdit, textDocument, edits);
|
||||||
|
struct WorkspaceEdit {
|
||||||
|
std::vector<TextDocumentEdit> documentChanges;
|
||||||
|
};
|
||||||
|
MAKE_REFLECT_STRUCT(WorkspaceEdit, documentChanges);
|
||||||
|
|
||||||
// completion
|
// completion
|
||||||
enum class CompletionTriggerKind {
|
enum class CompletionTriggerKind {
|
||||||
@ -139,7 +144,7 @@ struct DocumentFormattingParam {
|
|||||||
};
|
};
|
||||||
struct DocumentOnTypeFormattingParam {
|
struct DocumentOnTypeFormattingParam {
|
||||||
TextDocumentIdentifier textDocument;
|
TextDocumentIdentifier textDocument;
|
||||||
lsPosition position;
|
Position position;
|
||||||
std::string ch;
|
std::string ch;
|
||||||
FormattingOptions options;
|
FormattingOptions options;
|
||||||
};
|
};
|
||||||
@ -173,6 +178,21 @@ struct WorkspaceSymbolParam {
|
|||||||
// ccls extensions
|
// ccls extensions
|
||||||
std::vector<std::string> folders;
|
std::vector<std::string> folders;
|
||||||
};
|
};
|
||||||
|
MAKE_REFLECT_STRUCT(WorkspaceFolder, uri, name);
|
||||||
|
|
||||||
|
MAKE_REFLECT_TYPE_PROXY(ErrorCode);
|
||||||
|
MAKE_REFLECT_STRUCT(ResponseError, code, message);
|
||||||
|
MAKE_REFLECT_STRUCT(Position, line, character);
|
||||||
|
MAKE_REFLECT_STRUCT(lsRange, start, end);
|
||||||
|
MAKE_REFLECT_STRUCT(Location, uri, range);
|
||||||
|
MAKE_REFLECT_TYPE_PROXY(SymbolKind);
|
||||||
|
MAKE_REFLECT_STRUCT(TextDocumentIdentifier, uri);
|
||||||
|
MAKE_REFLECT_STRUCT(TextDocumentItem, uri, languageId, version, text);
|
||||||
|
MAKE_REFLECT_STRUCT(TextEdit, range, newText);
|
||||||
|
MAKE_REFLECT_STRUCT(VersionedTextDocumentIdentifier, uri, version);
|
||||||
|
MAKE_REFLECT_STRUCT(Diagnostic, range, severity, code, source, message);
|
||||||
|
MAKE_REFLECT_STRUCT(ShowMessageParam, type, message);
|
||||||
|
MAKE_REFLECT_TYPE_PROXY(LanguageId);
|
||||||
|
|
||||||
// TODO llvm 8 llvm::unique_function
|
// TODO llvm 8 llvm::unique_function
|
||||||
template <typename Res>
|
template <typename Res>
|
||||||
|
@ -20,12 +20,12 @@ namespace ccls {
|
|||||||
namespace {
|
namespace {
|
||||||
struct Param {
|
struct Param {
|
||||||
TextDocumentIdentifier textDocument;
|
TextDocumentIdentifier textDocument;
|
||||||
lsPosition position;
|
Position position;
|
||||||
std::string direction;
|
std::string direction;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(Param, textDocument, position, direction);
|
MAKE_REFLECT_STRUCT(Param, textDocument, position, direction);
|
||||||
|
|
||||||
Maybe<Range> FindParent(QueryFile *file, Position pos) {
|
Maybe<Range> FindParent(QueryFile *file, Pos pos) {
|
||||||
Maybe<Range> parent;
|
Maybe<Range> parent;
|
||||||
for (auto [sym, refcnt] : file->symbol2refcnt)
|
for (auto [sym, refcnt] : file->symbol2refcnt)
|
||||||
if (refcnt > 0 && sym.extent.Valid() && sym.extent.start <= pos &&
|
if (refcnt > 0 && sym.extent.Valid() && sym.extent.start <= pos &&
|
||||||
@ -47,12 +47,12 @@ void MessageHandler::ccls_navigate(Reader &reader,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
WorkingFile *wfile = wfiles->GetFileByFilename(file->def->path);
|
WorkingFile *wfile = wfiles->GetFileByFilename(file->def->path);
|
||||||
lsPosition ls_pos = param.position;
|
Position ls_pos = param.position;
|
||||||
if (wfile && wfile->index_lines.size())
|
if (wfile && wfile->index_lines.size())
|
||||||
if (auto line = wfile->GetIndexPosFromBufferPos(ls_pos.line,
|
if (auto line = wfile->GetIndexPosFromBufferPos(ls_pos.line,
|
||||||
&ls_pos.character, false))
|
&ls_pos.character, false))
|
||||||
ls_pos.line = *line;
|
ls_pos.line = *line;
|
||||||
Position pos{(int16_t)ls_pos.line, (int16_t)ls_pos.character};
|
Pos pos{(int16_t)ls_pos.line, (int16_t)ls_pos.character};
|
||||||
|
|
||||||
Maybe<Range> res;
|
Maybe<Range> res;
|
||||||
switch (param.direction[0]) {
|
switch (param.direction[0]) {
|
||||||
|
@ -95,7 +95,7 @@ ParseIncludeLineResult ParseIncludeLine(const std::string &line) {
|
|||||||
// significantly snappier completion experience as vscode is easily overloaded
|
// significantly snappier completion experience as vscode is easily overloaded
|
||||||
// when given 1000+ completion items.
|
// when given 1000+ completion items.
|
||||||
void FilterCandidates(CompletionList &result, const std::string &complete_text,
|
void FilterCandidates(CompletionList &result, const std::string &complete_text,
|
||||||
lsPosition begin_pos, lsPosition end_pos,
|
Position begin_pos, Position end_pos,
|
||||||
const std::string &buffer_line) {
|
const std::string &buffer_line) {
|
||||||
assert(begin_pos.line == end_pos.line);
|
assert(begin_pos.line == end_pos.line);
|
||||||
auto &items = result.items;
|
auto &items = result.items;
|
||||||
@ -126,7 +126,7 @@ void FilterCandidates(CompletionList &result, const std::string &complete_text,
|
|||||||
// Order of textEdit and additionalTextEdits is unspecified.
|
// Order of textEdit and additionalTextEdits is unspecified.
|
||||||
auto &edits = item.additionalTextEdits;
|
auto &edits = item.additionalTextEdits;
|
||||||
if (edits.size() && edits[0].range.end == begin_pos) {
|
if (edits.size() && edits[0].range.end == begin_pos) {
|
||||||
lsPosition start = edits[0].range.start, end = edits[0].range.end;
|
Position start = edits[0].range.start, end = edits[0].range.end;
|
||||||
item.textEdit.range.start = start;
|
item.textEdit.range.start = start;
|
||||||
item.textEdit.newText = edits[0].newText + item.textEdit.newText;
|
item.textEdit.newText = edits[0].newText + item.textEdit.newText;
|
||||||
if (start.line == begin_pos.line && item.filterText) {
|
if (start.line == begin_pos.line && item.filterText) {
|
||||||
@ -482,8 +482,8 @@ void MessageHandler::textDocument_completion(CompletionParam ¶m,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string completion_text;
|
std::string completion_text;
|
||||||
lsPosition end_pos = param.position;
|
Position end_pos = param.position;
|
||||||
lsPosition begin_pos = file->FindStableCompletionSource(
|
Position begin_pos = file->FindStableCompletionSource(
|
||||||
param.position, &completion_text, &end_pos);
|
param.position, &completion_text, &end_pos);
|
||||||
|
|
||||||
ParseIncludeLineResult preprocess = ParseIncludeLine(buffer_line);
|
ParseIncludeLineResult preprocess = ParseIncludeLine(buffer_line);
|
||||||
|
@ -55,7 +55,7 @@ void MessageHandler::textDocument_definition(TextDocumentPositionParam ¶m,
|
|||||||
std::vector<Location> result;
|
std::vector<Location> result;
|
||||||
Maybe<Use> on_def;
|
Maybe<Use> on_def;
|
||||||
WorkingFile *wfile = wfiles->GetFileByFilename(file->def->path);
|
WorkingFile *wfile = wfiles->GetFileByFilename(file->def->path);
|
||||||
lsPosition &ls_pos = param.position;
|
Position &ls_pos = param.position;
|
||||||
|
|
||||||
for (SymbolRef sym : FindSymbolsAtLocation(wfile, file, ls_pos, true)) {
|
for (SymbolRef sym : FindSymbolsAtLocation(wfile, file, ls_pos, true)) {
|
||||||
// Special cases which are handled:
|
// Special cases which are handled:
|
||||||
@ -107,7 +107,7 @@ void MessageHandler::textDocument_definition(TextDocumentPositionParam ¶m,
|
|||||||
}
|
}
|
||||||
// Find the best match of the identifier at point.
|
// Find the best match of the identifier at point.
|
||||||
if (!range) {
|
if (!range) {
|
||||||
lsPosition position = param.position;
|
Position position = param.position;
|
||||||
const std::string &buffer = wfile->buffer_content;
|
const std::string &buffer = wfile->buffer_content;
|
||||||
std::string_view query = LexIdentifierAroundPos(position, buffer);
|
std::string_view query = LexIdentifierAroundPos(position, buffer);
|
||||||
std::string_view short_query = query;
|
std::string_view short_query = query;
|
||||||
|
@ -43,14 +43,9 @@ WorkspaceEdit BuildWorkspaceEdit(DB *db, WorkingFiles *wfiles, SymbolRef sym,
|
|||||||
path_to_edit[file_id].textDocument.version = working_file->version;
|
path_to_edit[file_id].textDocument.version = working_file->version;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEdit edit;
|
TextEdit &edit = path_to_edit[file_id].edits.emplace_back();
|
||||||
edit.range = ls_location->range;
|
edit.range = ls_location->range;
|
||||||
edit.newText = new_text;
|
edit.newText = new_text;
|
||||||
|
|
||||||
// vscode complains if we submit overlapping text edits.
|
|
||||||
auto &edits = path_to_edit[file_id].edits;
|
|
||||||
if (std::find(edits.begin(), edits.end(), edit) == edits.end())
|
|
||||||
edits.push_back(edit);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
WorkspaceEdit edit;
|
WorkspaceEdit edit;
|
||||||
|
@ -155,10 +155,10 @@ void MessageHandler::textDocument_signatureHelp(
|
|||||||
static CompleteConsumerCache<SignatureHelp> cache;
|
static CompleteConsumerCache<SignatureHelp> cache;
|
||||||
|
|
||||||
std::string path = param.textDocument.uri.GetPath();
|
std::string path = param.textDocument.uri.GetPath();
|
||||||
lsPosition begin_pos = param.position;
|
Position begin_pos = param.position;
|
||||||
if (WorkingFile *file = wfiles->GetFileByFilename(path)) {
|
if (WorkingFile *file = wfiles->GetFileByFilename(path)) {
|
||||||
std::string completion_text;
|
std::string completion_text;
|
||||||
lsPosition end_pos = param.position;
|
Position end_pos = param.position;
|
||||||
begin_pos = file->FindStableCompletionSource(param.position,
|
begin_pos = file->FindStableCompletionSource(param.position,
|
||||||
&completion_text, &end_pos);
|
&completion_text, &end_pos);
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ limitations under the License.
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
namespace ccls {
|
namespace ccls {
|
||||||
Position Position::FromString(const std::string &encoded) {
|
Pos Pos::FromString(const std::string &encoded) {
|
||||||
char *p = const_cast<char *>(encoded.c_str());
|
char *p = const_cast<char *>(encoded.c_str());
|
||||||
int16_t line = int16_t(strtol(p, &p, 10)) - 1;
|
int16_t line = int16_t(strtol(p, &p, 10)) - 1;
|
||||||
assert(*p == ':');
|
assert(*p == ':');
|
||||||
@ -31,14 +31,14 @@ Position Position::FromString(const std::string &encoded) {
|
|||||||
return {line, column};
|
return {line, column};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Position::ToString() {
|
std::string Pos::ToString() {
|
||||||
char buf[99];
|
char buf[99];
|
||||||
snprintf(buf, sizeof buf, "%d:%d", line + 1, column + 1);
|
snprintf(buf, sizeof buf, "%d:%d", line + 1, column + 1);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
Range Range::FromString(const std::string &encoded) {
|
Range Range::FromString(const std::string &encoded) {
|
||||||
Position start, end;
|
Pos start, end;
|
||||||
char *p = const_cast<char *>(encoded.c_str());
|
char *p = const_cast<char *>(encoded.c_str());
|
||||||
start.line = int16_t(strtol(p, &p, 10)) - 1;
|
start.line = int16_t(strtol(p, &p, 10)) - 1;
|
||||||
assert(*p == ':');
|
assert(*p == ':');
|
||||||
@ -57,11 +57,11 @@ Range Range::FromString(const std::string &encoded) {
|
|||||||
bool Range::Contains(int line, int column) const {
|
bool Range::Contains(int line, int column) const {
|
||||||
if (line > INT16_MAX)
|
if (line > INT16_MAX)
|
||||||
return false;
|
return false;
|
||||||
Position p{int16_t(line), int16_t(std::min(column, INT16_MAX))};
|
Pos p{int16_t(line), int16_t(std::min(column, INT16_MAX))};
|
||||||
return !(p < start) && p < end;
|
return !(p < start) && p < end;
|
||||||
}
|
}
|
||||||
|
|
||||||
Range Range::RemovePrefix(Position position) const {
|
Range Range::RemovePrefix(Pos position) const {
|
||||||
return {std::min(std::max(position, start), end), end};
|
return {std::min(std::max(position, start), end), end};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,15 +73,15 @@ std::string Range::ToString() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Position
|
// Position
|
||||||
void Reflect(Reader &visitor, Position &value) {
|
void Reflect(Reader &visitor, Pos &value) {
|
||||||
if (visitor.Format() == SerializeFormat::Json) {
|
if (visitor.Format() == SerializeFormat::Json) {
|
||||||
value = Position::FromString(visitor.GetString());
|
value = Pos::FromString(visitor.GetString());
|
||||||
} else {
|
} else {
|
||||||
Reflect(visitor, value.line);
|
Reflect(visitor, value.line);
|
||||||
Reflect(visitor, value.column);
|
Reflect(visitor, value.column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Reflect(Writer &visitor, Position &value) {
|
void Reflect(Writer &visitor, Pos &value) {
|
||||||
if (visitor.Format() == SerializeFormat::Json) {
|
if (visitor.Format() == SerializeFormat::Json) {
|
||||||
std::string output = value.ToString();
|
std::string output = value.ToString();
|
||||||
visitor.String(output.c_str(), output.size());
|
visitor.String(output.c_str(), output.size());
|
||||||
|
@ -22,37 +22,37 @@ limitations under the License.
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace ccls {
|
namespace ccls {
|
||||||
struct Position {
|
struct Pos {
|
||||||
int16_t line = -1;
|
int16_t line = -1;
|
||||||
int16_t column = -1;
|
int16_t column = -1;
|
||||||
|
|
||||||
static Position FromString(const std::string &encoded);
|
static Pos FromString(const std::string &encoded);
|
||||||
|
|
||||||
bool Valid() const { return line >= 0; }
|
bool Valid() const { return line >= 0; }
|
||||||
std::string ToString();
|
std::string ToString();
|
||||||
|
|
||||||
// Compare two Positions and check if they are equal. Ignores the value of
|
// Compare two Positions and check if they are equal. Ignores the value of
|
||||||
// |interesting|.
|
// |interesting|.
|
||||||
bool operator==(const Position &o) const {
|
bool operator==(const Pos &o) const {
|
||||||
return line == o.line && column == o.column;
|
return line == o.line && column == o.column;
|
||||||
}
|
}
|
||||||
bool operator<(const Position &o) const {
|
bool operator<(const Pos &o) const {
|
||||||
if (line != o.line)
|
if (line != o.line)
|
||||||
return line < o.line;
|
return line < o.line;
|
||||||
return column < o.column;
|
return column < o.column;
|
||||||
}
|
}
|
||||||
bool operator<=(const Position &o) const { return !(o < *this); }
|
bool operator<=(const Pos &o) const { return !(o < *this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Range {
|
struct Range {
|
||||||
Position start;
|
Pos start;
|
||||||
Position end;
|
Pos end;
|
||||||
|
|
||||||
static Range FromString(const std::string &encoded);
|
static Range FromString(const std::string &encoded);
|
||||||
|
|
||||||
bool Valid() const { return start.Valid(); }
|
bool Valid() const { return start.Valid(); }
|
||||||
bool Contains(int line, int column) const;
|
bool Contains(int line, int column) const;
|
||||||
Range RemovePrefix(Position position) const;
|
Range RemovePrefix(Pos position) const;
|
||||||
|
|
||||||
std::string ToString();
|
std::string ToString();
|
||||||
|
|
||||||
@ -67,8 +67,8 @@ struct Range {
|
|||||||
// Reflection
|
// Reflection
|
||||||
class Reader;
|
class Reader;
|
||||||
class Writer;
|
class Writer;
|
||||||
void Reflect(Reader &visitor, Position &value);
|
void Reflect(Reader &visitor, Pos &value);
|
||||||
void Reflect(Writer &visitor, Position &value);
|
void Reflect(Writer &visitor, Pos &value);
|
||||||
void Reflect(Reader &visitor, Range &value);
|
void Reflect(Reader &visitor, Range &value);
|
||||||
void Reflect(Writer &visitor, Range &value);
|
void Reflect(Writer &visitor, Range &value);
|
||||||
} // namespace ccls
|
} // namespace ccls
|
||||||
@ -87,4 +87,4 @@ template <> struct hash<ccls::Range> {
|
|||||||
};
|
};
|
||||||
} // namespace std
|
} // namespace std
|
||||||
|
|
||||||
MAKE_HASHABLE(ccls::Position, t.line, t.column);
|
MAKE_HASHABLE(ccls::Pos, t.line, t.column);
|
||||||
|
@ -155,8 +155,8 @@ std::vector<Use> GetUsesForAllDerived(DB *db, QueryFunc &root) {
|
|||||||
std::optional<lsRange> GetLsRange(WorkingFile *wfile,
|
std::optional<lsRange> GetLsRange(WorkingFile *wfile,
|
||||||
const Range &location) {
|
const Range &location) {
|
||||||
if (!wfile || wfile->index_lines.empty())
|
if (!wfile || wfile->index_lines.empty())
|
||||||
return lsRange{lsPosition{location.start.line, location.start.column},
|
return lsRange{Position{location.start.line, location.start.column},
|
||||||
lsPosition{location.end.line, location.end.column}};
|
Position{location.end.line, location.end.column}};
|
||||||
|
|
||||||
int start_column = location.start.column, end_column = location.end.column;
|
int start_column = location.start.column, end_column = location.end.column;
|
||||||
std::optional<int> start = wfile->GetBufferPosFromIndexPos(
|
std::optional<int> start = wfile->GetBufferPosFromIndexPos(
|
||||||
@ -177,8 +177,7 @@ std::optional<lsRange> GetLsRange(WorkingFile *wfile,
|
|||||||
if (*start == *end && start_column > end_column)
|
if (*start == *end && start_column > end_column)
|
||||||
end_column = start_column;
|
end_column = start_column;
|
||||||
|
|
||||||
return lsRange{lsPosition{*start, start_column},
|
return lsRange{Position{*start, start_column}, Position{*end, end_column}};
|
||||||
lsPosition{*end, end_column}};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentUri GetLsDocumentUri(DB *db, int file_id, std::string *path) {
|
DocumentUri GetLsDocumentUri(DB *db, int file_id, std::string *path) {
|
||||||
@ -278,8 +277,7 @@ std::optional<SymbolInformation> GetSymbolInfo(DB *db, SymbolIdx sym,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile *wfile,
|
std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile *wfile,
|
||||||
QueryFile *file,
|
QueryFile *file, Position &ls_pos,
|
||||||
lsPosition &ls_pos,
|
|
||||||
bool smallest) {
|
bool smallest) {
|
||||||
std::vector<SymbolRef> symbols;
|
std::vector<SymbolRef> symbols;
|
||||||
// If multiVersion > 0, index may not exist and thus index_lines is empty.
|
// If multiVersion > 0, index may not exist and thus index_lines is empty.
|
||||||
|
@ -50,7 +50,7 @@ std::optional<SymbolInformation> GetSymbolInfo(DB *db, SymbolIdx sym,
|
|||||||
|
|
||||||
std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile *working_file,
|
std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile *working_file,
|
||||||
QueryFile *file,
|
QueryFile *file,
|
||||||
lsPosition &ls_pos,
|
Position &ls_pos,
|
||||||
bool smallest = false);
|
bool smallest = false);
|
||||||
|
|
||||||
template <typename Fn> void WithEntity(DB *db, SymbolIdx sym, Fn &&fn) {
|
template <typename Fn> void WithEntity(DB *db, SymbolIdx sym, Fn &&fn) {
|
||||||
|
@ -18,6 +18,7 @@ limitations under the License.
|
|||||||
#include "filesystem.hh"
|
#include "filesystem.hh"
|
||||||
#include "indexer.hh"
|
#include "indexer.hh"
|
||||||
#include "log.hh"
|
#include "log.hh"
|
||||||
|
#include "message_handler.hh"
|
||||||
#include "serializers/binary.hh"
|
#include "serializers/binary.hh"
|
||||||
#include "serializers/json.hh"
|
#include "serializers/json.hh"
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ constexpr int kMaxDiff = 20;
|
|||||||
// |kMaxColumnAlignSize|.
|
// |kMaxColumnAlignSize|.
|
||||||
constexpr int kMaxColumnAlignSize = 200;
|
constexpr int kMaxColumnAlignSize = 200;
|
||||||
|
|
||||||
lsPosition GetPositionForOffset(const std::string &content, int offset) {
|
Position GetPositionForOffset(const std::string &content, int offset) {
|
||||||
if (offset >= content.size())
|
if (offset >= content.size())
|
||||||
offset = (int)content.size() - 1;
|
offset = (int)content.size() - 1;
|
||||||
|
|
||||||
@ -341,9 +341,10 @@ std::optional<int> WorkingFile::GetIndexPosFromBufferPos(int line, int *column,
|
|||||||
index_lines, is_end);
|
index_lines, is_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string WorkingFile::FindClosestCallNameInBuffer(
|
std::string
|
||||||
lsPosition position, int *active_parameter,
|
WorkingFile::FindClosestCallNameInBuffer(Position position,
|
||||||
lsPosition *completion_position) const {
|
int *active_parameter,
|
||||||
|
Position *completion_position) const {
|
||||||
*active_parameter = 0;
|
*active_parameter = 0;
|
||||||
|
|
||||||
int offset = GetOffsetForPosition(position, buffer_content);
|
int offset = GetOffsetForPosition(position, buffer_content);
|
||||||
@ -389,10 +390,10 @@ std::string WorkingFile::FindClosestCallNameInBuffer(
|
|||||||
return buffer_content.substr(offset, start_offset - offset + 1);
|
return buffer_content.substr(offset, start_offset - offset + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
lsPosition
|
Position
|
||||||
WorkingFile::FindStableCompletionSource(lsPosition position,
|
WorkingFile::FindStableCompletionSource(Position position,
|
||||||
std::string *existing_completion,
|
std::string *existing_completion,
|
||||||
lsPosition *replace_end_pos) const {
|
Position *replace_end_pos) const {
|
||||||
int start_offset = GetOffsetForPosition(position, buffer_content);
|
int start_offset = GetOffsetForPosition(position, buffer_content);
|
||||||
int offset = start_offset;
|
int offset = start_offset;
|
||||||
|
|
||||||
@ -538,7 +539,7 @@ WorkingFiles::AsSnapshot(const std::vector<std::string> &filter_paths) {
|
|||||||
// text documents.
|
// text documents.
|
||||||
// We use a UTF-8 iterator to approximate UTF-16 in the specification (weird).
|
// We use a UTF-8 iterator to approximate UTF-16 in the specification (weird).
|
||||||
// This is good enough and fails only for UTF-16 surrogate pairs.
|
// This is good enough and fails only for UTF-16 surrogate pairs.
|
||||||
int GetOffsetForPosition(lsPosition pos, std::string_view content) {
|
int GetOffsetForPosition(Position pos, std::string_view content) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (; pos.line > 0 && i < content.size(); i++)
|
for (; pos.line > 0 && i < content.size(); i++)
|
||||||
if (content[i] == '\n')
|
if (content[i] == '\n')
|
||||||
@ -554,7 +555,7 @@ int GetOffsetForPosition(lsPosition pos, std::string_view content) {
|
|||||||
return int(i);
|
return int(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view LexIdentifierAroundPos(lsPosition position,
|
std::string_view LexIdentifierAroundPos(Position position,
|
||||||
std::string_view content) {
|
std::string_view content) {
|
||||||
int start = GetOffsetForPosition(position, content);
|
int start = GetOffsetForPosition(position, content);
|
||||||
int end = start + 1;
|
int end = start + 1;
|
||||||
|
@ -72,8 +72,8 @@ struct WorkingFile {
|
|||||||
// |completion_position| will be point to a good code completion location to
|
// |completion_position| will be point to a good code completion location to
|
||||||
// for fetching signatures.
|
// for fetching signatures.
|
||||||
std::string
|
std::string
|
||||||
FindClosestCallNameInBuffer(lsPosition position, int *active_parameter,
|
FindClosestCallNameInBuffer(Position position, int *active_parameter,
|
||||||
lsPosition *completion_position = nullptr) const;
|
Position *completion_position = nullptr) const;
|
||||||
|
|
||||||
// Returns a relatively stable completion position (it jumps back until there
|
// Returns a relatively stable completion position (it jumps back until there
|
||||||
// is a non-alphanumeric character).
|
// is a non-alphanumeric character).
|
||||||
@ -82,9 +82,9 @@ struct WorkingFile {
|
|||||||
// global completion.
|
// global completion.
|
||||||
// The out param |existing_completion| is set to any existing completion
|
// The out param |existing_completion| is set to any existing completion
|
||||||
// content the user has entered.
|
// content the user has entered.
|
||||||
lsPosition FindStableCompletionSource(lsPosition position,
|
Position FindStableCompletionSource(Position position,
|
||||||
std::string *existing_completion,
|
std::string *existing_completion,
|
||||||
lsPosition *replace_end_pos) const;
|
Position *replace_end_pos) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Compute index_to_buffer and buffer_to_index.
|
// Compute index_to_buffer and buffer_to_index.
|
||||||
@ -132,8 +132,8 @@ struct WorkingFiles {
|
|||||||
std::mutex files_mutex; // Protects |files|.
|
std::mutex files_mutex; // Protects |files|.
|
||||||
};
|
};
|
||||||
|
|
||||||
int GetOffsetForPosition(lsPosition pos, std::string_view content);
|
int GetOffsetForPosition(Position pos, std::string_view content);
|
||||||
|
|
||||||
std::string_view LexIdentifierAroundPos(lsPosition position,
|
std::string_view LexIdentifierAroundPos(Position position,
|
||||||
std::string_view content);
|
std::string_view content);
|
||||||
} // namespace ccls
|
} // namespace ccls
|
||||||
|
Loading…
Reference in New Issue
Block a user