-
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.
Fixed all warnings and addressed PR comments
- Loading branch information
Showing
4 changed files
with
88 additions
and
77 deletions.
There are no files selected for viewing
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
52 changes: 27 additions & 25 deletions
52
New_Extensibility_Model/Samples/RustLanguageServerProvider/RustExtension.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 |
---|---|---|
@@ -1,31 +1,33 @@ | ||
namespace RustLanguageServerProviderExtension | ||
{ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.VisualStudio.Extensibility; | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace RustLanguageServerProviderExtension; | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.VisualStudio.Extensibility; | ||
|
||
/// <summary> | ||
/// Extension entry point for the VisualStudio.Extensibility extension. | ||
/// </summary> | ||
[VisualStudioContribution] | ||
internal class RustExtension : Extension | ||
/// <summary> | ||
/// Extension entry point for the VisualStudio.Extensibility extension. | ||
/// </summary> | ||
[VisualStudioContribution] | ||
internal class RustExtension : Extension | ||
{ | ||
/// <inheritdoc/> | ||
public override ExtensionConfiguration ExtensionConfiguration => new() | ||
{ | ||
/// <inheritdoc/> | ||
public override ExtensionConfiguration ExtensionConfiguration => new() | ||
{ | ||
Metadata = new( | ||
id: "RustLspExtension.003741dc-9931-47c3-ad95-8804705cfbb9", | ||
version: this.ExtensionAssemblyVersion, | ||
publisherName: "Microsoft", | ||
displayName: "RustLspExtension", | ||
description: "Rust Language Server Extension"), | ||
}; | ||
Metadata = new( | ||
id: "RustLspExtension.003741dc-9931-47c3-ad95-8804705cfbb9", | ||
version: this.ExtensionAssemblyVersion, | ||
publisherName: "Microsoft", | ||
displayName: "RustLspExtension", | ||
description: "Rust Language Server Extension"), | ||
}; | ||
|
||
/// <inheritdoc /> | ||
protected override void InitializeServices(IServiceCollection serviceCollection) | ||
{ | ||
base.InitializeServices(serviceCollection); | ||
/// <inheritdoc /> | ||
protected override void InitializeServices(IServiceCollection serviceCollection) | ||
{ | ||
base.InitializeServices(serviceCollection); | ||
|
||
// You can configure dependency injection here by adding services to the serviceCollection. | ||
} | ||
// You can configure dependency injection here by adding services to the serviceCollection. | ||
} | ||
} |
110 changes: 59 additions & 51 deletions
110
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 |
---|---|---|
@@ -1,65 +1,73 @@ | ||
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; | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace RustLanguageServerProviderExtension; | ||
|
||
using System.Diagnostics; | ||
using System.IO.Pipelines; | ||
using System.Reflection; | ||
using Microsoft.VisualStudio.Extensibility; | ||
using Microsoft.VisualStudio.Extensibility.Editor; | ||
using Microsoft.VisualStudio.Extensibility.LanguageServer; | ||
using Microsoft.VisualStudio.RpcContracts.LanguageServerProvider; | ||
using Nerdbank.Streams; | ||
|
||
/// <inheritdoc/> | ||
[VisualStudioContribution] | ||
internal class RustLanguageServerProvider : LanguageServerProvider | ||
{ | ||
/// <summary> | ||
/// Gets the document type for rust code files. | ||
/// </summary> | ||
[VisualStudioContribution] | ||
internal class RustLanguageServerProvider : LanguageServerProvider | ||
public static DocumentTypeConfiguration RustDocumentType => new("rust") | ||
{ | ||
[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), | ||
}); | ||
FileExtensions = new[] { ".rs", ".rust" }, | ||
BaseDocumentType = LanguageServerBaseDocumentType, | ||
}; | ||
|
||
/// <inheritdoc/> | ||
public override Task<IDuplexPipe?> CreateServerConnectionAsync(CancellationToken cancellationToken) | ||
/// <inheritdoc/> | ||
public override LanguageServerProviderConfiguration LanguageServerProviderConfiguration => new( | ||
"%RustLspExtension.RustLanguageServerProvider.DisplayName%", | ||
new[] | ||
{ | ||
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; | ||
DocumentFilter.FromDocumentType(RustDocumentType), | ||
}); | ||
|
||
Process process = new Process(); | ||
process.StartInfo = info; | ||
/// <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; | ||
|
||
if (process.Start()) | ||
{ | ||
return Task.FromResult<IDuplexPipe?>(new DuplexPipe( | ||
PipeReader.Create(process.StandardOutput.BaseStream), | ||
PipeWriter.Create(process.StandardInput.BaseStream))); | ||
} | ||
#pragma warning disable CA2000 // The process is disposed after Visual Studio sends the stop command. | ||
Process process = new Process(); | ||
#pragma warning restore CA2000 // Dispose objects before losing scope. | ||
process.StartInfo = info; | ||
|
||
return Task.FromResult<IDuplexPipe?>(null); | ||
if (process.Start()) | ||
{ | ||
return Task.FromResult<IDuplexPipe?>(new DuplexPipe( | ||
PipeReader.Create(process.StandardOutput.BaseStream), | ||
PipeWriter.Create(process.StandardInput.BaseStream))); | ||
} | ||
|
||
/// <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 Task.FromResult<IDuplexPipe?>(null); | ||
} | ||
|
||
return base.OnServerInitializationResultAsync(serverInitializationResult, initializationFailureInfo, cancellationToken); | ||
/// <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); | ||
} | ||
} |
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