Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]
* Actually ingest InitializeParams.rootPath and .rootUri to determine workspace root:
- By @razzmatazz in https://github.com/razzmatazz/csharp-language-server/pull/283
* Add `--diagnose` command option to run basic diagnostics interactively
- By @razzmatazz in https://github.com/razzmatazz/csharp-language-server/pull/224
* Fix `textDocument/codeAction` for extracting an interface
Expand Down
1 change: 1 addition & 0 deletions src/CSharpLanguageServer/Handlers/Diagnostic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open Ionide.LanguageServerProtocol.JsonRpc
open CSharpLanguageServer.Roslyn.Conversions
open CSharpLanguageServer.State
open CSharpLanguageServer.Types
open CSharpLanguageServer.Util

[<RequireQualifiedAccess>]
module Diagnostic =
Expand Down
1 change: 1 addition & 0 deletions src/CSharpLanguageServer/Handlers/DocumentHighlight.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open Ionide.LanguageServerProtocol.JsonRpc

open CSharpLanguageServer.State
open CSharpLanguageServer.Roslyn.Conversions
open CSharpLanguageServer.Util

[<RequireQualifiedAccess>]
module DocumentHighlight =
Expand Down
35 changes: 32 additions & 3 deletions src/CSharpLanguageServer/Handlers/Initialization.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ open CSharpLanguageServer.State.ServerState
open CSharpLanguageServer.Types
open CSharpLanguageServer.Logging
open CSharpLanguageServer.Roslyn.Solution
open CSharpLanguageServer.Util


[<RequireQualifiedAccess>]
Expand Down Expand Up @@ -56,11 +57,39 @@ module Initialization =

initializeMSBuild ()

logger.LogDebug("handleInitialize: p.Capabilities={caps}", serialize p.Capabilities)
logger.LogDebug("handleInitialize: p.ClientInfo: {clientInfo}", p.ClientInfo |> Option.map serialize)

logger.LogDebug("handleInitialize: p.Capabilities: {caps}", serialize p.Capabilities)
context.Emit(ClientCapabilityChange p.Capabilities)

// TODO use p.RootUri
let rootPath = Directory.GetCurrentDirectory()
logger.LogDebug(
"handleInitialize: p.RootPath={rootPath}, p.RootUri={rootUri}, p.WorkspaceFolders={wf}",
p.RootPath,
p.RootUri,
p.WorkspaceFolders
)

// TODO use p.WorkspaceFolders
let rootPath, rootPathSource =
p.RootUri
|> Option.map (fun rootUri -> (Uri.toPath rootUri, "InitializeParams.rootUri"))
|> Option.orElse (
p.RootPath
|> Option.map (fun rootPath -> (rootPath, "InitializeParams.rootPath"))
)
|> Option.defaultValue (Directory.GetCurrentDirectory(), "Process CWD")

do!
windowShowMessage (
sprintf "csharp-ls: will use \"%s\" (%s) as workspace root path" rootPath rootPathSource
)

logger.LogDebug(
"handleInitialize: using rootPath \"{rootPath}\" from {rootPathSource}",
rootPath,
rootPathSource
)

context.Emit(RootPathChange rootPath)

// setup timer so actors get period ticks
Expand Down
23 changes: 0 additions & 23 deletions src/CSharpLanguageServer/Roslyn/Conversions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,6 @@ open Ionide.LanguageServerProtocol.Types
open CSharpLanguageServer.Util


module Uri =
// Unescape some necessary char before passing string to Uri.
// Can't use Uri.UnescapeDataString here. For example, if uri is "file:///z%3a/src/c%23/ProjDir" ("%3a" is
// ":" and "%23" is "#"), Uri.UnescapeDataString will unescape both "%3a" and "%23". Then Uri will think
/// "#/ProjDir" is Fragment instead of part of LocalPath.
let unescape (uri: string) = uri.Replace("%3a", ":", true, null)

let toPath (uri: string) =
Uri.UnescapeDataString(Uri(unescape uri).LocalPath)

let fromPath (path: string) =
let metadataPrefix = "$metadata$/"

if path.StartsWith metadataPrefix then
"csharp:/metadata/" + path.Substring metadataPrefix.Length
else
Uri(path).ToString()

let toWorkspaceFolder (uri: string) : WorkspaceFolder =
{ Uri = uri
Name = Uri.UnescapeDataString(Uri(unescape uri).Segments |> Array.last) }


module Position =
let fromLinePosition (pos: LinePosition) : Position =
{ Line = uint32 pos.Line
Expand Down
18 changes: 18 additions & 0 deletions src/CSharpLanguageServer/Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ let nonNull name (value: 'T when 'T: null) : 'T =
else
value

module Uri =
// Unescape some necessary char before passing string to Uri.
// Can't use Uri.UnescapeDataString here. For example, if uri is "file:///z%3a/src/c%23/ProjDir" ("%3a" is
// ":" and "%23" is "#"), Uri.UnescapeDataString will unescape both "%3a" and "%23". Then Uri will think
/// "#/ProjDir" is Fragment instead of part of LocalPath.
let unescape (uri: string) = uri.Replace("%3a", ":", true, null)

let toPath (uri: string) =
Uri.UnescapeDataString(Uri(unescape uri).LocalPath)

let fromPath (path: string) =
let metadataPrefix = "$metadata$/"

if path.StartsWith metadataPrefix then
"csharp:/metadata/" + path.Substring metadataPrefix.Length
else
Uri(path).ToString()

let parseFileUri s : string = Uri(s).LocalPath

let tryParseFileUri s : string option =
Expand Down