-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[script] add:: infrastructure for an language server script context
- Loading branch information
Showing
12 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
nw::script::DiagnosticLevel | ||
=========================== | ||
|
||
.. doxygenenum:: nw::script::DiagnosticLevel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
nw::script::DiagnosticType | ||
========================== | ||
|
||
.. doxygenenum:: nw::script::DiagnosticType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
nw::script::Diagnostic | ||
====================== | ||
|
||
.. doxygenstruct:: nw::script::Diagnostic | ||
:members: | ||
:undoc-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
nw::script::LspContext | ||
====================== | ||
|
||
.. doxygenstruct:: nw::script::LspContext | ||
:members: | ||
:undoc-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "LspContext.hpp" | ||
|
||
#include "Nss.hpp" | ||
|
||
namespace nw::script { | ||
|
||
LspContext::LspContext(std::string command_script) | ||
: Context(std::move(command_script)) | ||
{ | ||
} | ||
|
||
const std::vector<Diagnostic>& LspContext::diagnostics() const | ||
{ | ||
return diagnostics_; | ||
} | ||
|
||
void LspContext::lexical_diagnostic(Nss* script, std::string_view msg, bool is_warning, SourceLocation loc) | ||
{ | ||
Diagnostic result; | ||
result.type = DiagnosticType::lexical; | ||
result.level = is_warning ? DiagnosticLevel::warning : DiagnosticLevel::error; | ||
result.script = script ? script->name() : "<source>"; | ||
result.message = std::string(msg); | ||
result.location = loc; | ||
diagnostics_.push_back(std::move(result)); | ||
} | ||
|
||
void LspContext::parse_diagnostic(Nss* script, std::string_view msg, bool is_warning, SourceLocation loc) | ||
{ | ||
Diagnostic result; | ||
result.type = DiagnosticType::parse; | ||
result.level = is_warning ? DiagnosticLevel::warning : DiagnosticLevel::error; | ||
result.script = script ? script->name() : "<source>"; | ||
result.message = std::string(msg); | ||
result.location = loc; | ||
diagnostics_.push_back(std::move(result)); | ||
} | ||
|
||
void LspContext::semantic_diagnostic(Nss* script, std::string_view msg, bool is_warning, SourceLocation loc) | ||
{ | ||
Diagnostic result; | ||
result.type = DiagnosticType::semantic; | ||
result.level = is_warning ? DiagnosticLevel::warning : DiagnosticLevel::error; | ||
result.script = script ? script->name() : "<source>"; | ||
result.message = std::string(msg); | ||
result.location = loc; | ||
diagnostics_.push_back(std::move(result)); | ||
} | ||
|
||
} // namespace nw::script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include "Context.hpp" | ||
|
||
namespace nw::script { | ||
|
||
enum struct DiagnosticType { | ||
lexical, | ||
parse, | ||
semantic, | ||
}; | ||
|
||
enum struct DiagnosticLevel { | ||
warning, | ||
error, | ||
}; | ||
|
||
struct Diagnostic { | ||
DiagnosticType type; | ||
DiagnosticLevel level; | ||
std::string script; | ||
std::string message; | ||
SourceLocation location; | ||
}; | ||
|
||
struct LspContext : public Context { | ||
LspContext(std::string command_script = "nwscript"); | ||
virtual ~LspContext() = default; | ||
|
||
std::vector<Diagnostic> diagnostics_; | ||
|
||
const std::vector<Diagnostic>& diagnostics() const; | ||
|
||
virtual void lexical_diagnostic(Nss* script, std::string_view msg, bool is_warning, SourceLocation loc) override; | ||
virtual void parse_diagnostic(Nss* script, std::string_view msg, bool is_warning, SourceLocation loc) override; | ||
virtual void semantic_diagnostic(Nss* script, std::string_view msg, bool is_warning, SourceLocation loc) override; | ||
}; | ||
|
||
} // namespace nw::script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters