Skip to content

Commit

Permalink
Fixed some path issues with lsp uris
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico committed Apr 21, 2024
1 parent 964ae1b commit a0466e0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/misc/util.nim
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ template hasPrefix*(exp: untyped, prefix: string, v: untyped): untyped =

matches

func myNormalizedPath*(path: string): string = path.replace('\\', '/').strip(chars={'/'})

# type ArrayLike*[T] {.explain.} = concept x, var v
# x.low is int
# x.high is int
Expand Down
9 changes: 5 additions & 4 deletions src/text/language/language_server_lsp.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import std/[strutils, options, json, tables, uri, strformat, sequtils]
import scripting_api except DocumentEditor, TextDocumentEditor, AstDocumentEditor
import misc/[event, util, custom_logger, custom_async, myjsonutils, custom_unicode]
import platform/filesystem
import text/text_editor
import language_server_base, app, app_interface, config_provider, lsp_client
import workspaces/workspace as ws
Expand Down Expand Up @@ -179,16 +180,16 @@ method getDefinition*(self: LanguageServerLSP, filename: string, location: Curso
let parsedResponse = response.result

if parsedResponse.asLocation().getSome(location):
return Definition(filename: location.uri.decodeUrl.parseUri.path.myNormalizedPath, location: (line: location.`range`.start.line, column: location.`range`.start.character)).some
return Definition(filename: location.uri.decodeUrl.parseUri.path.normalizePathUnix, location: (line: location.`range`.start.line, column: location.`range`.start.character)).some

if parsedResponse.asLocationSeq().getSome(locations) and locations.len > 0:
let location = locations[0]
return Definition(filename: location.uri.decodeUrl.parseUri.path.myNormalizedPath, location: (line: location.`range`.start.line, column: location.`range`.start.character)).some
return Definition(filename: location.uri.decodeUrl.parseUri.path.normalizePathUnix, location: (line: location.`range`.start.line, column: location.`range`.start.character)).some

if parsedResponse.asLocationLinkSeq().getSome(locations) and locations.len > 0:
let location = locations[0]
return Definition(
filename: location.targetUri.decodeUrl.parseUri.path.myNormalizedPath,
filename: location.targetUri.decodeUrl.parseUri.path.normalizePathUnix,
location: (line: location.targetSelectionRange.start.line, column: location.targetSelectionRange.start.character)).some

log(lvlError, "No definition found")
Expand Down Expand Up @@ -319,7 +320,7 @@ method getSymbols*(self: LanguageServerLSP, filename: string): Future[seq[Symbol
location: (line: r.location.range.start.line, column: r.location.range.start.character),
name: r.name,
symbolType: symbolKind,
filename: r.location.uri.decodeUrl.parseUri.path.myNormalizedPath,
filename: r.location.uri.decodeUrl.parseUri.path.normalizePathUnix,
)

return completions
Expand Down
5 changes: 3 additions & 2 deletions src/text/language/lsp_client.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import std/[json, strutils, strformat, macros, options, tables, sets, uri, sequtils, sugar, os]
import misc/[custom_logger, async_http_client, websocket, util, event, myjsonutils, custom_async]
import platform/filesystem
import scripting/expose
from workspaces/workspace as ws import nil
import lsp_types
Expand Down Expand Up @@ -84,7 +85,7 @@ method recv(connection: LSPConnectionWebsocket, length: int): Future[string] {.a

method send(connection: LSPConnectionWebsocket, data: string): Future[void] = connection.websocket.send(data)

proc encodePathUri(path: string): string = path.myNormalizedPath.split("/").mapIt(it.encodeUrl(false)).join("/")
proc encodePathUri(path: string): string = path.normalizePathUnix.split("/").mapIt(it.encodeUrl(false)).join("/")

when defined(js):
# todo
Expand Down Expand Up @@ -246,7 +247,7 @@ proc cancelAllOf*(client: LSPClient, meth: string) =

proc initialize(client: LSPClient): Future[Response[JsonNode]] {.async.} =
var workspacePath = if client.workspaceFolders.len > 0:
client.workspaceFolders[0].myNormalizedPath.some
client.workspaceFolders[0].normalizePathUnix.some
else:
string.none

Expand Down

0 comments on commit a0466e0

Please sign in to comment.