Skip to content

Commit 53aa113

Browse files
authored
Merge branch 'lsp' into merges/main-to-lsp
2 parents fa0329b + 96bac02 commit 53aa113

File tree

17 files changed

+1051
-1
lines changed

17 files changed

+1051
-1
lines changed

VisualFSharp.sln

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FSharp.Editor.IntegrationTe
191191
EndProject
192192
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Benchmarks.Common", "tests\benchmarks\FSharp.Benchmarks.Common\FSharp.Benchmarks.Common.fsproj", "{6734FC6F-B5F3-45E1-9A72-720378BB49C9}"
193193
EndProject
194+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.LanguageServer", "src\FSharp.Compiler.LanguageServer\FSharp.Compiler.LanguageServer.fsproj", "{D72F6593-DB2D-47AC-8E15-8DCE8527972E}"
195+
EndProject
196+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.LanguageServer.Tests", "tests\FSharp.Compiler.LanguageServer.Tests\FSharp.Compiler.LanguageServer.Tests.fsproj", "{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388}"
197+
EndProject
198+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FSharp.VisualStudio.Extension", "src\FSharp.VisualStudio.Extension\FSharp.VisualStudio.Extension.csproj", "{E1013576-6257-47BA-AAFB-F95B68DAB1FF}"
199+
EndProject
194200
Global
195201
GlobalSection(SolutionConfigurationPlatforms) = preSolution
196202
Debug|Any CPU = Debug|Any CPU
@@ -1005,6 +1011,42 @@ Global
10051011
{6734FC6F-B5F3-45E1-9A72-720378BB49C9}.Release|Any CPU.Build.0 = Release|Any CPU
10061012
{6734FC6F-B5F3-45E1-9A72-720378BB49C9}.Release|x86.ActiveCfg = Release|Any CPU
10071013
{6734FC6F-B5F3-45E1-9A72-720378BB49C9}.Release|x86.Build.0 = Release|Any CPU
1014+
{D72F6593-DB2D-47AC-8E15-8DCE8527972E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1015+
{D72F6593-DB2D-47AC-8E15-8DCE8527972E}.Debug|Any CPU.Build.0 = Debug|Any CPU
1016+
{D72F6593-DB2D-47AC-8E15-8DCE8527972E}.Debug|x86.ActiveCfg = Debug|Any CPU
1017+
{D72F6593-DB2D-47AC-8E15-8DCE8527972E}.Debug|x86.Build.0 = Debug|Any CPU
1018+
{D72F6593-DB2D-47AC-8E15-8DCE8527972E}.Proto|Any CPU.ActiveCfg = Debug|Any CPU
1019+
{D72F6593-DB2D-47AC-8E15-8DCE8527972E}.Proto|Any CPU.Build.0 = Debug|Any CPU
1020+
{D72F6593-DB2D-47AC-8E15-8DCE8527972E}.Proto|x86.ActiveCfg = Debug|Any CPU
1021+
{D72F6593-DB2D-47AC-8E15-8DCE8527972E}.Proto|x86.Build.0 = Debug|Any CPU
1022+
{D72F6593-DB2D-47AC-8E15-8DCE8527972E}.Release|Any CPU.ActiveCfg = Release|Any CPU
1023+
{D72F6593-DB2D-47AC-8E15-8DCE8527972E}.Release|Any CPU.Build.0 = Release|Any CPU
1024+
{D72F6593-DB2D-47AC-8E15-8DCE8527972E}.Release|x86.ActiveCfg = Release|Any CPU
1025+
{D72F6593-DB2D-47AC-8E15-8DCE8527972E}.Release|x86.Build.0 = Release|Any CPU
1026+
{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1027+
{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388}.Debug|Any CPU.Build.0 = Debug|Any CPU
1028+
{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388}.Debug|x86.ActiveCfg = Debug|Any CPU
1029+
{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388}.Debug|x86.Build.0 = Debug|Any CPU
1030+
{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388}.Proto|Any CPU.ActiveCfg = Debug|Any CPU
1031+
{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388}.Proto|Any CPU.Build.0 = Debug|Any CPU
1032+
{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388}.Proto|x86.ActiveCfg = Debug|Any CPU
1033+
{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388}.Proto|x86.Build.0 = Debug|Any CPU
1034+
{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388}.Release|Any CPU.ActiveCfg = Release|Any CPU
1035+
{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388}.Release|Any CPU.Build.0 = Release|Any CPU
1036+
{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388}.Release|x86.ActiveCfg = Release|Any CPU
1037+
{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388}.Release|x86.Build.0 = Release|Any CPU
1038+
{E1013576-6257-47BA-AAFB-F95B68DAB1FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1039+
{E1013576-6257-47BA-AAFB-F95B68DAB1FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
1040+
{E1013576-6257-47BA-AAFB-F95B68DAB1FF}.Debug|x86.ActiveCfg = Debug|Any CPU
1041+
{E1013576-6257-47BA-AAFB-F95B68DAB1FF}.Debug|x86.Build.0 = Debug|Any CPU
1042+
{E1013576-6257-47BA-AAFB-F95B68DAB1FF}.Proto|Any CPU.ActiveCfg = Debug|Any CPU
1043+
{E1013576-6257-47BA-AAFB-F95B68DAB1FF}.Proto|Any CPU.Build.0 = Debug|Any CPU
1044+
{E1013576-6257-47BA-AAFB-F95B68DAB1FF}.Proto|x86.ActiveCfg = Debug|Any CPU
1045+
{E1013576-6257-47BA-AAFB-F95B68DAB1FF}.Proto|x86.Build.0 = Debug|Any CPU
1046+
{E1013576-6257-47BA-AAFB-F95B68DAB1FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
1047+
{E1013576-6257-47BA-AAFB-F95B68DAB1FF}.Release|Any CPU.Build.0 = Release|Any CPU
1048+
{E1013576-6257-47BA-AAFB-F95B68DAB1FF}.Release|x86.ActiveCfg = Release|Any CPU
1049+
{E1013576-6257-47BA-AAFB-F95B68DAB1FF}.Release|x86.Build.0 = Release|Any CPU
10081050
EndGlobalSection
10091051
GlobalSection(SolutionProperties) = preSolution
10101052
HideSolutionNode = FALSE
@@ -1084,6 +1126,7 @@ Global
10841126
{CBC96CC7-65AB-46EA-A82E-F6A788DABF80} = {F7876C9B-FB6A-4EFB-B058-D6967DB75FB2}
10851127
{E31F9B59-FCF1-4D04-8762-C7BB60285A7B} = {F7876C9B-FB6A-4EFB-B058-D6967DB75FB2}
10861128
{6734FC6F-B5F3-45E1-9A72-720378BB49C9} = {DFB6ADD7-3149-43D9-AFA0-FC4A818B472B}
1129+
{1E83A6C8-FA4D-42BD-B4A5-B7F9AAD1B388} = {CFE3259A-2D30-4EB0-80D5-E8B5F3D01449}
10871130
EndGlobalSection
10881131
GlobalSection(ExtensibilityGlobals) = postSolution
10891132
SolutionGuid = {48EDBBBE-C8EE-4E3C-8B19-97184A487B37}

src/Compiler/FSharp.Compiler.Service.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<InternalsVisibleTo Include="HistoricalBenchmark" />
7979
<InternalsVisibleTo Include="FSharp.Test.Utilities" />
8080
<InternalsVisibleTo Include="FSharp.Editor" />
81+
<InternalsVisibleTo Include="FSharp.Compiler.LanguageServer" />
8182
</ItemGroup>
8283

8384
<ItemGroup>

src/Compiler/Facilities/Hashing.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ module internal Md5Hasher =
4646
let private md5 =
4747
new ThreadLocal<_>(fun () -> System.Security.Cryptography.MD5.Create())
4848

49-
let computeHash (bytes: byte array) = md5.Value.ComputeHash(bytes)
49+
let computeHash (bytes: byte array) =
50+
// md5.Value.ComputeHash(bytes) TODO: the threadlocal is not working in new VS extension
51+
ignore md5
52+
let md5 = System.Security.Cryptography.MD5.Create()
53+
md5.ComputeHash(bytes)
5054

5155
let empty = Array.empty
5256

src/Compiler/Service/FSharpProjectSnapshot.fs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,60 @@ and [<Experimental("This FCS API is experimental and subject to change.")>] FSha
673673

674674
FSharpProjectSnapshot.FromOptions(options, getFileSnapshot)
675675

676+
static member FromResponseFile(responseFile: FileInfo, projectFileName) =
677+
if not responseFile.Exists then
678+
failwith $"%s{responseFile.FullName} does not exist"
679+
680+
let compilerArgs = File.ReadAllLines responseFile.FullName
681+
682+
let fsharpFileExtensions = set [| ".fs"; ".fsi"; ".fsx" |]
683+
684+
let isFSharpFile (file: string) =
685+
Set.exists (fun (ext: string) -> file.EndsWith(ext, StringComparison.Ordinal)) fsharpFileExtensions
686+
687+
let isReference: string -> bool = _.StartsWith("-r:")
688+
689+
let fsharpFiles =
690+
compilerArgs
691+
|> Array.choose (fun (line: string) ->
692+
if not (isFSharpFile line) then
693+
None
694+
else
695+
696+
let fullPath = Path.Combine(responseFile.DirectoryName, line)
697+
if not (File.Exists fullPath) then None else Some fullPath)
698+
|> Array.toList
699+
700+
let referencesOnDisk =
701+
compilerArgs |> Seq.filter isReference |> Seq.map _.Substring(3) |> Seq.toList
702+
703+
let otherOptions =
704+
compilerArgs
705+
|> Seq.filter (not << isReference)
706+
|> Seq.filter (not << isFSharpFile)
707+
|> Seq.toList
708+
709+
FSharpProjectSnapshot.Create(
710+
projectFileName = projectFileName,
711+
projectId = None,
712+
sourceFiles = (fsharpFiles |> List.map FSharpFileSnapshot.CreateFromFileSystem),
713+
referencesOnDisk =
714+
(referencesOnDisk
715+
|> List.map (fun x ->
716+
{
717+
Path = x
718+
LastModified = FileSystem.GetLastWriteTimeShim(x)
719+
})),
720+
otherOptions = otherOptions,
721+
referencedProjects = [],
722+
isIncompleteTypeCheckEnvironment = false,
723+
useScriptResolutionRules = false,
724+
loadTime = DateTime.Now,
725+
unresolvedReferences = None,
726+
originalLoadReferences = [],
727+
stamp = None
728+
)
729+
676730
let rec internal snapshotToOptions (projectSnapshot: ProjectSnapshotBase<_>) =
677731
{
678732
ProjectFileName = projectSnapshot.ProjectFileName
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module FSharp.Compiler.LanguageServer.Executable
2+
3+
open System
4+
open StreamJsonRpc
5+
6+
[<EntryPoint>]
7+
let main argv =
8+
9+
let jsonRpc = new JsonRpc(Console.OpenStandardOutput(), Console.OpenStandardInput())
10+
11+
let s = new FSharpLanguageServer(jsonRpc, (LspLogger Console.Out.Write))
12+
13+
jsonRpc.StartListening()
14+
15+
async {
16+
while true do
17+
do! Async.Sleep 1000
18+
}
19+
|> Async.RunSynchronously
20+
21+
0
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup Label="Package References">
9+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
10+
<PackageReference Include="Microsoft.CommonLanguageServerProtocol.Framework" Version="4.10.0-2.24105.6" />
11+
<!--<PackageReference Include="Microsoft.CodeAnalysis.LanguageServer.Protocol" Version="4.10.0-1.24067.1" />-->
12+
<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Protocol" Version="17.10.13-preview" />
13+
<PackageReference Include="StreamJsonRpc" Version="2.17.13" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<NuspecProperty Include="FSharpCorePackageVersion=$(FSCorePackageVersionValue)" Condition="'$(VersionSuffix)'==''" />
18+
<NuspecProperty Include="FSharpCorePackageVersion=$(FSCorePackageVersionValue)-$(VersionSuffix)" Condition="'$(VersionSuffix)'!=''" />
19+
</ItemGroup>
20+
21+
<ItemGroup Condition="'$(FSHARPCORE_USE_PACKAGE)' != 'true'">
22+
<ProjectReference Include="$(MSBuildThisFileDirectory)..\FSharp.Core\FSharp.Core.fsproj" />
23+
</ItemGroup>
24+
25+
<ItemGroup Condition="'$(FSHARPCORE_USE_PACKAGE)' == 'true'">
26+
<PackageReference Include="FSharp.Core" Version="$(FSharpCoreShippedPackageVersionValue)" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<Compile Include="Utils.fs" />
31+
<Compile Include="FSharpWorkspace.fs" />
32+
<Compile Include="FSharpLanguageServer.fs" />
33+
<Compile Include="Executable.fs" />
34+
</ItemGroup>
35+
36+
<ItemGroup>
37+
<!--<ProjectReference Include="..\..\..\roslyn\src\Features\LanguageServer\Microsoft.CommonLanguageServerProtocol.Framework\Microsoft.CommonLanguageServerProtocol.Framework.csproj" />-->
38+
<ProjectReference Include="..\Compiler\FSharp.Compiler.Service.fsproj" />
39+
</ItemGroup>
40+
41+
</Project>

0 commit comments

Comments
 (0)