Skip to content

Commit

Permalink
fix: Language server may crash on hover
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera committed Jan 18, 2023
1 parent 44b11db commit 36c8895
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions parser_library/src/lsp/text_data_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ std::string_view text_data_view::get_line(size_t line) const
return {};
size_t line_end_i = (line < line_indices.size() - 1) ? line_indices[line + 1] : text.size();
size_t line_len = line_end_i - line_indices[line];
return text.substr(line_indices[line], line_len);
return std::string_view(text).substr(line_indices[line], line_len);
}

std::string_view text_data_view::get_line_beginning_at(position pos) const
Expand All @@ -38,7 +38,7 @@ std::string_view text_data_view::get_line_beginning_at(position pos) const
return {};
size_t line_end_i = workspaces::file_impl::index_from_position(text, line_indices, pos);
size_t line_len = line_end_i - line_indices[pos.line];
return text.substr(line_indices[pos.line], line_len);
return std::string_view(text).substr(line_indices[pos.line], line_len);
}

char text_data_view::get_character_before(position pos) const
Expand All @@ -55,14 +55,14 @@ std::string_view text_data_view::get_range_content(range r) const
size_t end_i = workspaces::file_impl::index_from_position(text, line_indices, r.end);
if (start_i >= text.size())
return {};
return text.substr(start_i, end_i - start_i);
return std::string_view(text).substr(start_i, end_i - start_i);
}

std::string_view text_data_view::get_lines_beginning_at(position pos) const
{
if (pos.line >= line_indices.size())
return {};
return text.substr(line_indices[pos.line]);
return std::string_view(text).substr(line_indices[pos.line]);
}

size_t text_data_view::get_number_of_lines() const { return line_indices.size(); }
Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/lsp/text_data_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace hlasm_plugin::parser_library::lsp {

class text_data_view
{
std::string_view text;
std::string text; // FIXME: no longer view due to lifetime issues
std::vector<size_t> line_indices;

public:
Expand Down

0 comments on commit 36c8895

Please sign in to comment.