-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
344 additions
and
211 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...Extensibility_Model/Samples/RustLanguageServerProvider/.vsextension/string-resources.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"RustLspExtension.RustLanguageServerProvider.DisplayName": "Rust Analyzer LSP server" | ||
} |
31 changes: 31 additions & 0 deletions
31
New_Extensibility_Model/Samples/RustLanguageServerProvider/ExtensionEntrypoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace RustLanguageServerProviderExtension | ||
{ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.VisualStudio.Extensibility; | ||
|
||
/// <summary> | ||
/// Extension entry point for the VisualStudio.Extensibility extension. | ||
/// </summary> | ||
[VisualStudioContribution] | ||
internal class ExtensionEntrypoint : Extension | ||
{ | ||
/// <inheritdoc/> | ||
public override ExtensionConfiguration ExtensionConfiguration => new() | ||
{ | ||
Metadata = new( | ||
id: "RustLspExtension.003741dc-9931-47c3-ad95-8804705cfbb9", | ||
version: this.ExtensionAssemblyVersion, | ||
publisherName: "Publisher name", | ||
displayName: "RustLspExtension", | ||
description: "Extension description"), | ||
}; | ||
|
||
/// <inheritdoc /> | ||
protected override void InitializeServices(IServiceCollection serviceCollection) | ||
{ | ||
base.InitializeServices(serviceCollection); | ||
|
||
// You can configure dependency injection here by adding services to the serviceCollection. | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
New_Extensibility_Model/Samples/RustLanguageServerProvider/RustLanguageServerProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
namespace RustLanguageServerProviderExtension | ||
{ | ||
using Microsoft.VisualStudio.Extensibility; | ||
using Microsoft.VisualStudio.Extensibility.Editor; | ||
using Microsoft.VisualStudio.Extensibility.LanguageServer; | ||
using Microsoft.VisualStudio.RpcContracts.LanguageServerProvider; | ||
using Nerdbank.Streams; | ||
using System.Diagnostics; | ||
using System.IO.Pipelines; | ||
using System.Reflection; | ||
|
||
[VisualStudioContribution] | ||
internal class RustLanguageServerProvider : LanguageServerProvider | ||
{ | ||
public RustLanguageServerProvider(ExtensionCore container, VisualStudioExtensibility extensibilityObject) | ||
: base(container, extensibilityObject) | ||
{ | ||
} | ||
|
||
[VisualStudioContribution] | ||
public static DocumentTypeConfiguration RustDocumentType => new("rust") | ||
{ | ||
FileExtensions = new[] { ".rs", ".rust" }, | ||
BaseDocumentType = LanguageServerBaseDocumentType, | ||
}; | ||
|
||
/// <inheritdoc/> | ||
public override LanguageServerProviderConfiguration LanguageServerProviderConfiguration => new( | ||
"%RustLspExtension.RustLanguageServerProvider.DisplayName%", | ||
new[] | ||
{ | ||
DocumentFilter.FromDocumentType(RustDocumentType), | ||
}); | ||
|
||
/// <inheritdoc/> | ||
public override Task<IDuplexPipe?> CreateServerConnectionAsync(CancellationToken cancellationToken) | ||
{ | ||
ProcessStartInfo info = new ProcessStartInfo(); | ||
info.FileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, @"rust-analyzer.exe"); | ||
info.RedirectStandardInput = true; | ||
info.RedirectStandardOutput = true; | ||
info.UseShellExecute = false; | ||
info.CreateNoWindow = true; | ||
|
||
Process process = new Process(); | ||
process.StartInfo = info; | ||
|
||
if (process.Start()) | ||
{ | ||
return Task.FromResult<IDuplexPipe?>(new DuplexPipe( | ||
PipeReader.Create(process.StandardOutput.BaseStream), | ||
PipeWriter.Create(process.StandardInput.BaseStream))); | ||
} | ||
|
||
return Task.FromResult<IDuplexPipe?>(null); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override Task OnServerInitializationResultAsync(ServerInitializationResult serverInitializationResult, LanguageServerInitializationFailureInfo? initializationFailureInfo, CancellationToken cancellationToken) | ||
{ | ||
if (serverInitializationResult == ServerInitializationResult.Failed) | ||
{ | ||
// Log telemetry for failure and disable the server from being activated again. | ||
this.Enabled = false; | ||
} | ||
|
||
return base.OnServerInitializationResultAsync(serverInitializationResult, initializationFailureInfo, cancellationToken); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
New_Extensibility_Model/Samples/RustLanguageServerProvider/RustLanguageServerProvider.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<!-- The VisualStudio.Extensibility preview packages are available from the azure-public/vside/msft_consumption feed --> | ||
<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/azure-public/vside/_packaging/msft_consumption/nuget/v3/index.json;$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="rust-analyzer.exe" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.9.42-preview-1" /> | ||
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.9.42-preview-1" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.