nixd
Loading...
Searching...
No Matches
Convert.cpp
Go to the documentation of this file.
1#include "Convert.h"
2
4
6
7#include <llvm/ADT/StringRef.h>
8
9using namespace lspserver;
10
11int nixd::getLSPSeverity(nixf::Diagnostic::DiagnosticKind Kind) {
12 switch (nixf::Diagnostic::severity(Kind)) {
15 return 1;
17 return 2;
19 return 3;
21 return 4;
22 }
23 assert(false && "Invalid severity");
25}
26
28 const nixf::LexerCursor &P) {
29 return lspserver::offsetToPosition(Code, P.offset());
30}
31
35
39
41 const nixf::LexerCursorRange &R) {
42 return lspserver::Range{toLSPPosition(Code, R.lCur()),
43 toLSPPosition(Code, R.rCur())};
44}
45
46llvm::SmallVector<lspserver::DiagnosticTag, 1>
47nixd::toLSPTags(const std::vector<nixf::DiagnosticTag> &Tags) {
48 llvm::SmallVector<lspserver::DiagnosticTag, 1> Result;
49 Result.reserve(Tags.size());
50 for (const nixf::DiagnosticTag &Tag : Tags) {
51 switch (Tag) {
53 Result.emplace_back(DiagnosticTag::Unnecessary);
54 break;
56 Result.emplace_back(DiagnosticTag::Deprecated);
57 break;
58 }
59 }
60 return Result;
61}
Convert between LSP and nixf types.
@ DS_Warning
A warning.
Definition Diagnostic.h:160
@ DS_Fatal
shouldn't eval the code, e.g. parsing error.
Definition Diagnostic.h:156
@ DS_Info
An information.
Definition Diagnostic.h:162
@ DS_Error
trigger an error in nix, but we can recover & eval the code.
Definition Diagnostic.h:158
static Severity severity(DiagnosticKind Kind)
LexerCursor lCur() const
Definition Range.h:116
LexerCursor rCur() const
Definition Range.h:117
A point in the source file.
Definition Range.h:57
std::size_t offset() const
Offset in the source file, starting from 0.
Definition Range.h:102
Whether current platform treats paths case insensitively.
Definition Connection.h:11
bool fromJSON(const llvm::json::Value &, URIForFile &, llvm::json::Path)
Position offsetToPosition(llvm::StringRef Code, size_t Offset)
int getLSPSeverity(nixf::Diagnostic::DiagnosticKind Kind)
Definition Convert.cpp:11
nixf::PositionRange toNixfRange(const lspserver::Range &P)
Definition Convert.cpp:36
lspserver::Position toLSPPosition(llvm::StringRef Code, const nixf::LexerCursor &P)
Definition Convert.cpp:27
nixf::Position toNixfPosition(const lspserver::Position &P)
Definition Convert.cpp:32
lspserver::Range toLSPRange(llvm::StringRef Code, const nixf::LexerCursorRange &R)
Definition Convert.cpp:40
llvm::SmallVector< lspserver::DiagnosticTag, 1 > toLSPTags(const std::vector< nixf::DiagnosticTag > &Tags)
Definition Convert.cpp:47
DiagnosticTag
Definition Diagnostic.h:74
int line
Line position in a document (zero-based).
Position start
The range's start position.
Position end
The range's end position.