Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

use current directory if none is supplied in InitializeParams #82

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions nimlangserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,14 @@ proc getWorkspaceConfiguration(ls: LanguageServer): Future[NlsConfig] {.async.}
debug "Failed to parse the configuration."
result = NlsConfig()

proc getRootPath(ip: InitializeParams): string =
if ip.rootUri == "":
return fmt"file://{getCurrentDir()}".uriToPath
return ip.rootUri.uriToPath

proc getProjectFile(fileUri: string, ls: LanguageServer): Future[string] {.async.} =
let
rootPath = AbsoluteDir(ls.initializeParams.rootUri.uriToPath)
rootPath = AbsoluteDir(ls.initializeParams.getRootPath)
pathRelativeToRoot = string(AbsoluteFile(fileUri).relativeTo(rootPath))
mappings = ls.getWorkspaceConfiguration.await().projectMapping.get(@[])

Expand Down Expand Up @@ -419,7 +424,7 @@ proc checkProject(ls: LanguageServer, uri: string): Future[void] {.async, gcsafe

proc getWorkingDir(ls: LanguageServer, path: string): Future[string] {.async.} =
let
rootPath = AbsoluteDir(ls.initializeParams.rootUri.uriToPath)
rootPath = AbsoluteDir(ls.initializeParams.getRootPath)
pathRelativeToRoot = string(AbsoluteFile(path).relativeTo(rootPath))
mapping = ls.getWorkspaceConfiguration.await().workingDirectoryMapping.get(@[])

Expand Down Expand Up @@ -729,7 +734,7 @@ proc prepareRename(ls: LanguageServer, params: PrepareRenameParams,
if def.len == 0:
return newJNull()
# Check if the symbol belongs to the project
let projectDir = ls.initializeParams.rootUri.uriToPath
let projectDir = ls.initializeParams.getRootPath
if def[0].filePath.isRelativeTo(projectDir):
return %def[0].toLocation().range

Expand All @@ -743,7 +748,7 @@ proc rename(ls: LanguageServer, params: RenameParams, id: int): Future[Workspace
position: params.position
))
# Build up list of edits that the client needs to perform for each file
let projectDir = ls.initializeParams.rootUri.uriToPath
let projectDir = ls.initializeParams.getRootPath
var edits = newJObject()
for reference in references:
# Only rename symbols in the project.
Expand Down