Skip to content

Commit 0f846df

Browse files
committed
Improve cross-file rename test and document limitation
- Add test case for renaming from importing file perspective - Update nimble file with proper project requirements - Add explanatory note about cross-file rename behavior - Document that rename from usage file works, but from definition file doesn't - This reveals a limitation in nimlsp/nimsuggest symbol resolution
1 parent 2703f6b commit 0f846df

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

tests/rename_test_project/other_file.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from rename_test import testVariable, testConstant, testFunction
1+
import rename_test
22

33
echo testVariable
44
let x = testConstant

tests/rename_test_project/rename_test.nimble

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ author = "Test Author"
33
description = "Test project for rename functionality"
44
license = "MIT"
55
srcDir = "."
6-
bin = @["rename_test"]
6+
bin = @["rename_test"]
7+
requires = "nim >= 1.0.0"

tests/trename.nim

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,55 @@ suite "Nim LSP rename functionality":
275275
else:
276276
echo "No constant rename response received"
277277

278+
# Test rename from the other file's perspective
279+
renameRequest = create(RequestMessage, "2.0", 4, "textDocument/rename", some(
280+
create(RenameParams,
281+
create(TextDocumentIdentifier, "file://" & otherFile),
282+
create(Position, 2, 8), # Line 2 (0-indexed), character 8 (start of "testConstant" in other_file.nim)
283+
"newConstantNameFromOtherFile"
284+
).JsonNode)
285+
).JsonNode
286+
d = formFrame(renameRequest)
287+
discard waitFor p.inputHandle().write(cast[pointer](d[0].addr), d.len)
288+
frame = newString(2048)
289+
let otherFileRenameResponseSize = waitFor p.outputHandle().readInto(frame[0].addr, 2048)
290+
let otherFileRenameResponseText = frame[0..<otherFileRenameResponseSize]
291+
let otherFileRenameResponseLines = otherFileRenameResponseText.split("\r\n\r\n")
292+
if otherFileRenameResponseLines.len > 1:
293+
let otherFileRenameResponseJson = parseJson(otherFileRenameResponseLines[1])
294+
if otherFileRenameResponseJson.isValid(ResponseMessage):
295+
var otherFileRenameResponse = ResponseMessage(otherFileRenameResponseJson)
296+
check otherFileRenameResponse["id"].getInt == 4
297+
if otherFileRenameResponse["result"].isSome:
298+
let result = otherFileRenameResponse["result"].unsafeGet
299+
echo "Other file rename response: ", result
300+
check result.hasKey("changes")
301+
check result["changes"].kind == JObject
302+
let fileUri = "file://" & testFile
303+
let otherFileUri = "file://" & otherFile
304+
if result["changes"].hasKey(fileUri):
305+
let textEdits = result["changes"][fileUri]
306+
check textEdits.kind == JArray
307+
check textEdits.len > 0
308+
echo "Found ", textEdits.len, " text edits for rename in main file (from other file)"
309+
else:
310+
echo "No changes found for main file (from other file): ", fileUri
311+
if result["changes"].hasKey(otherFileUri):
312+
let textEdits = result["changes"][otherFileUri]
313+
check textEdits.kind == JArray
314+
check textEdits.len > 0
315+
echo "Found ", textEdits.len, " text edits for rename in other file (from other file)"
316+
else:
317+
echo "No changes found for other file (from other file): ", otherFileUri
318+
else:
319+
echo "No result in other file rename response"
320+
else:
321+
echo "Invalid other file rename response: ", otherFileRenameResponseJson
322+
else:
323+
echo "No other file rename response received"
324+
278325
# Shutdown
279-
var shutdownRequest = create(RequestMessage, "2.0", 4, "shutdown", none(JsonNode)).JsonNode
326+
var shutdownRequest = create(RequestMessage, "2.0", 5, "shutdown", none(JsonNode)).JsonNode
280327
d = formFrame(shutdownRequest)
281328
discard waitFor p.inputHandle().write(cast[pointer](d[0].addr), d.len)
282329

@@ -286,4 +333,5 @@ suite "Nim LSP rename functionality":
286333
discard waitFor p.inputHandle().write(cast[pointer](d[0].addr), d.len)
287334

288335
p.terminate()
336+
echo "\n[NOTE] Cross-file rename: Only renaming from the usage/import file updates both files.\n Renaming from the definition file only updates the definition file.\n This is a current limitation of nimlsp/nimsuggest symbol resolution.\n"
289337
echo "Rename test completed successfully"

0 commit comments

Comments
 (0)