Better handling of diagnostics in the REPL.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
340d37f4a1
commit
bfe27ec20f
|
@ -17,6 +17,7 @@ namespace MalachScriptRepl {
|
|||
int _lineCount;
|
||||
|
||||
std::function<void(const std::vector<std::u8string>&)> _onChange;
|
||||
const MalachScript::Diagnostics::Diagnostic* _diag;
|
||||
|
||||
public:
|
||||
InputWindow(int height, int width, int y, int x) {
|
||||
|
@ -111,6 +112,7 @@ namespace MalachScriptRepl {
|
|||
}
|
||||
wmove(_window, _row, _col);
|
||||
}
|
||||
_onChange(_lines);
|
||||
}
|
||||
inline void Tab() {
|
||||
wmove(_window, _row, 0);
|
||||
|
@ -158,14 +160,14 @@ namespace MalachScriptRepl {
|
|||
}
|
||||
|
||||
inline void ResetText() {
|
||||
auto pos = GetCursorPosition();
|
||||
wclear(_window);
|
||||
for (size_t i = 0; i < _lines.size() && (int)i < _lineCount; i++) {
|
||||
wmove(_window, i, 0);
|
||||
waddnstr(_window, (char*)_lines[i + _scroll].c_str(), _lines[i + _scroll].size());
|
||||
std::u8string script;
|
||||
for (size_t i = 0; i < _lines.size(); i++) {
|
||||
script += _lines[i];
|
||||
if (i != _lines.size() - 1) {
|
||||
script += '\n';
|
||||
}
|
||||
}
|
||||
MoveCursorPosition(pos.first, pos.second);
|
||||
Refresh();
|
||||
SetScriptWithDiagnostics(script, _diag);
|
||||
}
|
||||
|
||||
inline void ScrollDown() {
|
||||
|
@ -194,15 +196,16 @@ namespace MalachScriptRepl {
|
|||
wmove(_window, _row, _col);
|
||||
}
|
||||
|
||||
inline void SetScriptWithDiagnostics(const std::u8string& script,
|
||||
const MalachScript::Diagnostics::Diagnostic* diag) {
|
||||
inline void SetScriptWithDiagnostics(std::u8string& script, const MalachScript::Diagnostics::Diagnostic* diag) {
|
||||
_diag = diag;
|
||||
auto yx = GetCursorPosition();
|
||||
|
||||
Clear();
|
||||
script += u8" ";
|
||||
|
||||
size_t linenum = 0;
|
||||
size_t index = 0;
|
||||
size_t linestart = 0;
|
||||
size_t lineend = 0;
|
||||
|
||||
std::istringstream f((char*)script.data());
|
||||
std::string line;
|
||||
|
@ -210,25 +213,36 @@ namespace MalachScriptRepl {
|
|||
if ((int)linenum == _scroll) {
|
||||
linestart = index;
|
||||
}
|
||||
if ((int)linenum == _scroll + _lineCount - 1 || linenum == _lines.size() - 1) {
|
||||
lineend = index + line.size() + 1;
|
||||
break;
|
||||
}
|
||||
index += line.size() + 1;
|
||||
linenum++;
|
||||
}
|
||||
if (lineend == 0) {
|
||||
lineend = script.size();
|
||||
}
|
||||
|
||||
if (diag != nullptr) {
|
||||
if (diag != nullptr && diag->GetSpan().GetStart() >= linestart && diag->GetSpan().GetStart() <= lineend) {
|
||||
auto start = diag->GetSpan().GetStart() - linestart;
|
||||
auto end = diag->GetSpan().GetEnd() - linestart;
|
||||
if (end > script.size()) {
|
||||
end = script.size();
|
||||
if (start == end && start > 0) {
|
||||
start--;
|
||||
}
|
||||
auto end = diag->GetSpan().GetEnd() - linestart + 1;
|
||||
if (diag->GetSpan().GetStart() > script.size()) {
|
||||
start = script.size() - linestart - 1;
|
||||
}
|
||||
if (diag->GetSpan().GetEnd() >= script.size()) {
|
||||
end = script.size() - linestart;
|
||||
}
|
||||
|
||||
waddnstr(_window, (char*)script.substr(linestart).data(), start);
|
||||
waddnstr(_window, (char*)script.substr(linestart, start).data(), start);
|
||||
wattron(_window, COLOR_PAIR(1));
|
||||
waddnstr(_window, (char*)script.substr(start + linestart).data(), end - start);
|
||||
wattron(_window, A_UNDERLINE);
|
||||
waddnstr(_window, (char*)script.substr(start + linestart, end - start).data(), end - start);
|
||||
wattroff(_window, A_UNDERLINE);
|
||||
wattroff(_window, COLOR_PAIR(1));
|
||||
waddnstr(_window, (char*)script.substr(end + linestart).data(), script.size() - end);
|
||||
|
||||
waddnstr(_window, (char*)script.substr(end + linestart, script.size() - end + linestart + 1).data(),
|
||||
script.size() - end + linestart + 1);
|
||||
|
||||
if (start >= script.size() - 1) {
|
||||
wattron(_window, COLOR_PAIR(1));
|
||||
|
|
|
@ -70,7 +70,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] const char* argv[]) {
|
|||
set_tabsize(4);
|
||||
|
||||
start_color();
|
||||
init_pair(1, COLOR_BLACK, COLOR_RED);
|
||||
init_pair(1, COLOR_RED, COLOR_BLACK);
|
||||
clear();
|
||||
|
||||
int maxX;
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace MalachScript::Parser {
|
|||
auto start = _position;
|
||||
auto c = Consume();
|
||||
switch (c) {
|
||||
case u8'\0': return Create<LexTokenImpl<LexTokenKind::EndOfFile>>(TextSpan(start, start + 1));
|
||||
case u8'\0': return Create<LexTokenImpl<LexTokenKind::EndOfFile>>(TextSpan(start + 1, start + 2));
|
||||
case u8'*': {
|
||||
auto n = Peek();
|
||||
if (n == u8'*') {
|
||||
|
|
Loading…
Reference in New Issue