Skip to content

Commit 1b97eaa

Browse files
committed
fix: Incorrect horizontal scrollbar displayed.
After the recent changes to scrolling the code uses the longest line in the source code to determine if and how big horizontal scrollbars are needed. Instead of the computationally expensive calculation of the longest line, we let the lexer record it when it generates the token stream. It turns out that the lexer is also getting token streams for the included and imported files which leads to the problem. Instead of letting the lexer do both the recording and the reporting of the longest line in the code we use the preprocessor to intercept the value before the included and imported files are preprocessed. The fix is incomplete unless an upcoming PR to ViewPatterneditor.cpp where the longest line size is sent to the text editor is also included.
1 parent 7729025 commit 1b97eaa

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

lib/include/pl/core/lexer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace pl::core {
4949
std::optional<u128> parseInteger(std::string_view literal);
5050

5151
Token makeToken(const Token& token, size_t length = 1);
52-
static Token makeTokenAt(const Token& token, Location& location, size_t length = 1);
52+
Token makeTokenAt(const Token& token, Location& location, size_t length = 1);
5353
void addToken(const Token& token);
5454
bool hasTheLineEnded(const char &ch) {
5555
if(ch == '\n') {

lib/include/pl/core/preprocessor.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ namespace pl::core {
3636
void addStatementHandler(const Token::Keyword &statementType, const api::StatementHandler &handler);
3737
void removePragmaHandler(const std::string &pragmaType);
3838
void removeDirectiveHandler(const Token::Directive &directiveType);
39-
39+
size_t getLongestLineLength() const { return m_longestLineLength; }
40+
void setLongestLineLength(size_t length) { m_longestLineLength = length; }
4041
void validateOutput();
4142

4243
[[nodiscard]] const std::vector<ExcludedLocation>& getExcludedLocations() const {
@@ -162,7 +163,7 @@ namespace pl::core {
162163
std::vector<Token> m_result;
163164
std::vector<Token> m_output;
164165
std::vector<std::string> m_namespaces;
165-
166+
size_t m_longestLineLength = 0;
166167
api::Source* m_source = nullptr;
167168

168169
bool m_onlyIncludeOnce = false;

lib/source/pl/core/lexer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,13 @@ namespace pl::core {
458458
Token Lexer::makeToken(const Token &token, const size_t length) {
459459
auto location = this->location();
460460
location.length = length;
461+
m_longestLineLength = std::max(m_longestLineLength, location.column + location.length);
461462
return { token.type, token.value, location };
462463
}
463464

464465
Token Lexer::makeTokenAt(const Token &token, Location& location, const size_t length) {
465466
location.length = length;
467+
m_longestLineLength = std::max(m_longestLineLength, location.column + location.length);
466468
return { token.type, token.value, location };
467469
}
468470

lib/source/pl/core/preprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ namespace pl::core {
601601
this->error(item);
602602
return { m_output, collectErrors() };
603603
}
604-
604+
setLongestLineLength(lexer->getLongestLineLength());
605605
m_token = m_result.begin();
606606
m_initialized = true;
607607
while (!eof())

0 commit comments

Comments
 (0)