Skip to content

Commit

Permalink
[wip] lsp: Fixed module instantiation renaming
Browse files Browse the repository at this point in the history
In the current state of the commit it is NOT acutally fixed, but it is a
WIP towards a solution

Signed-off-by: Jan Bylicki <[email protected]>
  • Loading branch information
jbylicki committed Jun 16, 2023
1 parent f523773 commit feb3e8e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
6 changes: 3 additions & 3 deletions common/lsp/lsp-protocol.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ DocumentLink:
range: Range
target?: string # DocumentUri

# -- textDocument/prepareRename (TODO(jbylicki): check that requires project + active symbol table #1189)
# -- textDocument/prepareRename
PrepareRenameParams:
<: TextDocumentPositionParams

# Response: Range[]
# Response: Range

# -- textDocument/rename (TODO(jbylicki): check that requires project + active symbol table #1189)
# -- textDocument/rename
RenameParams:
<: TextDocumentPositionParams
newName: string
Expand Down
20 changes: 9 additions & 11 deletions verilog/tools/ls/symbol-table-handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,22 +248,22 @@ absl::string_view SymbolTableHandler::GetTokenAtTextDocumentPosition(

verible::LineColumnRange
SymbolTableHandler::GetTokenRangeAtTextDocumentPosition(
const verible::lsp::TextDocumentPositionParams &params,
const verible::lsp::TextDocumentPositionParams &document_cursor,
const verilog::BufferTrackerContainer &parsed_buffers) {
const verilog::BufferTracker *tracker =
parsed_buffers.FindBufferTrackerOrNull(params.textDocument.uri);
parsed_buffers.FindBufferTrackerOrNull(document_cursor.textDocument.uri);
if (!tracker) {
VLOG(1) << "Could not find buffer with URI " << params.textDocument.uri;
VLOG(1) << "Could not find buffer with URI " << document_cursor.textDocument.uri;
return {};
}
std::shared_ptr<const ParsedBuffer> parsedbuffer = tracker->current();
if (!parsedbuffer) {
VLOG(1) << "Buffer not found among opened buffers: "
<< params.textDocument.uri;
<< document_cursor.textDocument.uri;
return {};
}
const verible::LineColumn cursor{params.position.line,
params.position.character};
const verible::LineColumn cursor{document_cursor.position.line,
document_cursor.position.character};
const verible::TextStructureView &text = parsedbuffer->parser().Data();

const verible::TokenInfo cursor_token = text.FindTokenAt(cursor);
Expand Down Expand Up @@ -342,17 +342,14 @@ std::vector<verible::lsp::Location> SymbolTableHandler::FindReferencesLocations(
return locations;
}

verible::lsp::Range SymbolTableHandler::FindRenameLocations(
verible::lsp::Range SymbolTableHandler::FindRenameableRangeAtCursor(
const verible::lsp::PrepareRenameParams &params,
const verilog::BufferTrackerContainer &parsed_buffers) {
Prepare();
verible::LineColumnRange symbol =
GetTokenRangeAtTextDocumentPosition(params, parsed_buffers);
verible::lsp::Range range;
range.start.line = symbol.start.line;
range.start.character = symbol.start.column;
range.end.line = symbol.end.line;
range.end.character = symbol.end.column;
range = RangeFromLineColumn(symbol);
return range;
}

Expand Down Expand Up @@ -393,6 +390,7 @@ SymbolTableHandler::FindRenameLocationsAndCreateEdits(
.changes = {},
};
edit.changes = file_edit_pairs;
std::cerr << "SIZE: " <<edit.changes[locations[0].uri].size() << std::endl;
return edit;
}
void SymbolTableHandler::CollectReferencesReferenceComponents(
Expand Down
4 changes: 2 additions & 2 deletions verilog/tools/ls/symbol-table-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SymbolTableHandler {
const verible::lsp::ReferenceParams &params,
const verilog::BufferTrackerContainer &parsed_buffers);

verible::lsp::Range FindRenameLocations(
verible::lsp::Range FindRenameableRangeAtCursor(
const verible::lsp::PrepareRenameParams &params,
const verilog::BufferTrackerContainer &parsed_buffers);
// Provide new parsed content for the given path. If "content" is nullptr,
Expand Down Expand Up @@ -97,7 +97,7 @@ class SymbolTableHandler {

// TODO(jbylicki): Add docstring
verible::LineColumnRange GetTokenRangeAtTextDocumentPosition(
const verible::lsp::TextDocumentPositionParams &params,
const verible::lsp::TextDocumentPositionParams &document_cursor,
const verilog::BufferTrackerContainer &parsed_buffers);

// Returns the Location of the symbol name in source file
Expand Down
2 changes: 1 addition & 1 deletion verilog/tools/ls/verilog-language-server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void VerilogLanguageServer::SetRequestHandlers() {
dispatcher_.AddRequestHandler(
"textDocument/prepareRename",
[this](const verible::lsp::PrepareRenameParams &p) {
return symbol_table_handler_.FindRenameLocations(p, parsed_buffers_);
return symbol_table_handler_.FindRenameableRangeAtCursor(p, parsed_buffers_);
});
dispatcher_.AddRequestHandler(
"textDocument/rename", [this](const verible::lsp::RenameParams &p) {
Expand Down

0 comments on commit feb3e8e

Please sign in to comment.