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
33 changes: 33 additions & 0 deletions VSFSharpExtension.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B4A1E626-4A48-4977-B291-219882DB3413}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FSharp.VisualStudio.Extension", "src\FSharp.VisualStudio.Extension\FSharp.VisualStudio.Extension.csproj", "{14B9AB0E-2FC0-43F1-9775-20C262202D12}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.LanguageServer", "src\FSharp.Compiler.LanguageServer\FSharp.Compiler.LanguageServer.fsproj", "{7EDDFB35-2428-4433-8ABF-47233480B746}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{14B9AB0E-2FC0-43F1-9775-20C262202D12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{14B9AB0E-2FC0-43F1-9775-20C262202D12}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14B9AB0E-2FC0-43F1-9775-20C262202D12}.Release|Any CPU.ActiveCfg = Release|Any CPU
{14B9AB0E-2FC0-43F1-9775-20C262202D12}.Release|Any CPU.Build.0 = Release|Any CPU
{7EDDFB35-2428-4433-8ABF-47233480B746}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7EDDFB35-2428-4433-8ABF-47233480B746}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7EDDFB35-2428-4433-8ABF-47233480B746}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7EDDFB35-2428-4433-8ABF-47233480B746}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{14B9AB0E-2FC0-43F1-9775-20C262202D12} = {B4A1E626-4A48-4977-B291-219882DB3413}
EndGlobalSection
EndGlobal
5 changes: 4 additions & 1 deletion src/Compiler/Service/FSharpProjectSnapshot.fs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,9 @@ and [<Experimental("This FCS API is experimental and subject to change.")>] FSha

let compilerArgs = File.ReadAllLines responseFile.FullName

FSharpProjectSnapshot.FromCommandLineArgs(compilerArgs, responseFile.DirectoryName, projectFileName)

static member FromCommandLineArgs(compilerArgs: string array, directoryPath: string, projectFileName) =
let fsharpFileExtensions = set [| ".fs"; ".fsi"; ".fsx" |]

let isFSharpFile (file: string) =
Expand All @@ -693,7 +696,7 @@ and [<Experimental("This FCS API is experimental and subject to change.")>] FSha
None
else

let fullPath = Path.Combine(responseFile.DirectoryName, line)
let fullPath = Path.Combine(directoryPath, line)
if not (File.Exists fullPath) then None else Some fullPath)
|> Array.toList

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.10.17-preview-1" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.10.17-preview-1" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.10.2059-preview-3-g914e66a9d4" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.10.2059-preview-3-g914e66a9d4" />

<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Protocol.Internal" Version="17.10.14-preview" />
<PackageReference Include="Microsoft.VisualStudio.LanguageServer.Protocol.Internal" Version="17.10.34-preview" />

<PackageReference Include="Microsoft.VisualStudio.ProjectSystem.Query" Version="17.10.105-pre" />
</ItemGroup>

<ItemGroup>
Expand Down
59 changes: 47 additions & 12 deletions src/FSharp.VisualStudio.Extension/FSharpLanguageServerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,46 @@ internal class FSharpLanguageServerProvider : LanguageServerProvider
public override async Task<IDuplexPipe?> CreateServerConnectionAsync(CancellationToken cancellationToken)
{
var ws = this.Extensibility.Workspaces();
//var result = what.QueryProjectsAsync(project => project.With(p => p.Kind == "6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705"), cancellationToken).Result;
IQueryResults<IProjectSnapshot>? result = await ws.QueryProjectsAsync(project => project.With(p => new { p.ActiveConfigurations, p.Id, p.Guid }), cancellationToken);

var x = await ws.QuerySolutionAsync(solution => solution.With(s => new { s.Path, s.Guid, s.ActiveConfiguration, s.ActivePlatform }), cancellationToken);
IQueryResults<IProjectSnapshot>? result = await ws.QueryProjectsAsync(project => project
.With(p => p.ActiveConfigurations
.With(c => c.RuleResultsByRuleName("CompilerCommandLineArgs")
.With(r => r.RuleName)
.With(r => r.Items)))
.With(p => new { p.ActiveConfigurations, p.Id, p.Guid }), cancellationToken);


List<(string, string)> projectsAndCommandLineArgs = [];
foreach (var project in result)
{
project.Id.TryGetValue("ProjectPath", out var projectPath);

List<string> commandLineArgs = [];
if (projectPath != null)
{
// There can be multiple Active Configurations, e.g. one for net8.0 and one for net472
// TODO For now taking any single one of them, but we might actually want to pick specific one
var config = project.ActiveConfigurations.FirstOrDefault();
if (config != null)
{
foreach (var ruleResults in config.RuleResults)
{
// XXX Idk why `.Where` does not work with these IAsyncQuerable type
if (ruleResults?.RuleName == "CompilerCommandLineArguments")
{
// XXX Not sure why there would be more than one item for this rule result
// Taking first one, ignoring the rest
var args = ruleResults?.Items?.FirstOrDefault()?.Name;
if (args != null) commandLineArgs.Add(args);
}
}
}
if (commandLineArgs.Count > 0)
{
projectsAndCommandLineArgs.Add((projectPath, commandLineArgs[0]));
}
}

try
{
this.ProcessProject(project);
Expand All @@ -178,15 +211,17 @@ internal class FSharpLanguageServerProvider : LanguageServerProvider

try
{
// Some hardcoded projects before we create them from the ProjectQuery
var projectsRoot = @"D:\code";
var giraffe = FSharpProjectSnapshot.FromResponseFile(
new FileInfo(Path.Combine(projectsRoot, @"Giraffe\src\Giraffe\Giraffe.rsp")),
Path.Combine(projectsRoot, @"Giraffe\src\Giraffe\Giraffe.fsproj"));
var giraffeTests = FSharpProjectSnapshot.FromResponseFile(
new FileInfo(Path.Combine(projectsRoot, @"Giraffe\tests\Giraffe.Tests\Giraffe.Tests.rsp")),
Path.Combine(projectsRoot, @"Giraffe\tests\Giraffe.Tests\Giraffe.Tests.fsproj"));
workspace = FSharpWorkspace.Create([giraffe, giraffeTests]);
List<FSharpProjectSnapshot> snapshots = [];
foreach(var args in projectsAndCommandLineArgs)
{
var lines = args.Item2.Split(';'); // XXX Probably not robust enough
var path = args.Item1;

var snapshot = FSharpProjectSnapshot.FromCommandLineArgs(
lines, Path.GetDirectoryName(path), Path.GetFileName(path));
snapshots.Add(snapshot);
}
workspace = FSharpWorkspace.Create(snapshots);
}
catch
{
Expand Down