Skip to content

move to omnisharp 0.17.0 #1283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.PowerShell.EditorServices.Handlers;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
Expand Down Expand Up @@ -94,16 +95,18 @@ internal EditorContextService(
public async Task<ILspCurrentFileContext> GetCurrentLspFileContextAsync()
{
ClientEditorContext clientContext =
await _languageServer.SendRequest<GetEditorContextRequest, ClientEditorContext>(
await _languageServer.SendRequest<GetEditorContextRequest>(
"editor/getEditorContext",
new GetEditorContextRequest()).ConfigureAwait(false);
new GetEditorContextRequest())
.Returning<ClientEditorContext>(CancellationToken.None)
.ConfigureAwait(false);

return new LspCurrentFileContext(clientContext);
}

public Task OpenNewUntitledFileAsync()
{
return _languageServer.SendRequest<string>("editor/newFile", null);
return _languageServer.SendRequest<string>("editor/newFile", null).ReturningVoid(CancellationToken.None);
}

public Task OpenFileAsync(Uri fileUri) => OpenFileAsync(fileUri, preview: false);
Expand All @@ -114,12 +117,12 @@ public Task OpenFileAsync(Uri fileUri, bool preview)
{
FilePath = fileUri.LocalPath,
Preview = preview,
});
}).ReturningVoid(CancellationToken.None);
}

public Task CloseFileAsync(Uri fileUri)
{
return _languageServer.SendRequest("editor/closeFile", fileUri.LocalPath);
return _languageServer.SendRequest("editor/closeFile", fileUri.LocalPath).ReturningVoid(CancellationToken.None);
}

public Task SaveFileAsync(Uri fileUri) => SaveFileAsync(fileUri, null);
Expand All @@ -130,15 +133,15 @@ public Task SaveFileAsync(Uri oldFileUri, Uri newFileUri)
{
FilePath = oldFileUri.LocalPath,
NewPath = newFileUri?.LocalPath,
});
}).ReturningVoid(CancellationToken.None);
}

public Task SetSelectionAsync(ILspFileRange range)
{
return _languageServer.SendRequest("editor/setSelection", new SetSelectionRequest
{
SelectionRange = range.ToOmnisharpRange()
});
}).ReturningVoid(CancellationToken.None);
}

public Task InsertTextAsync(Uri fileUri, string text, ILspFileRange range)
Expand All @@ -148,7 +151,7 @@ public Task InsertTextAsync(Uri fileUri, string text, ILspFileRange range)
FilePath = fileUri.LocalPath,
InsertText = text,
InsertRange = range.ToOmnisharpRange(),
});
}).ReturningVoid(CancellationToken.None);
}
}
}
13 changes: 7 additions & 6 deletions src/PowerShellEditorServices/Extensions/Api/EditorUIService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
Expand Down Expand Up @@ -112,12 +113,12 @@ public EditorUIService(ILanguageServer languageServer)
public async Task<string> PromptInputAsync(string message)
{
// The VSCode client currently doesn't use the Label field, so we ignore it
ShowInputPromptResponse response = await _languageServer.SendRequest<ShowInputPromptRequest, ShowInputPromptResponse>(
ShowInputPromptResponse response = await _languageServer.SendRequest<ShowInputPromptRequest>(
"powerShell/showInputPrompt",
new ShowInputPromptRequest
{
Name = message,
});
}).Returning<ShowInputPromptResponse>(CancellationToken.None);

if (response.PromptCancelled)
{
Expand All @@ -134,7 +135,7 @@ public async Task<IReadOnlyList<string>> PromptMultipleSelectionAsync(string mes
{
ChoiceDetails[] choiceDetails = GetChoiceDetails(choices);

ShowChoicePromptResponse response = await _languageServer.SendRequest<ShowChoicePromptRequest, ShowChoicePromptResponse>(
ShowChoicePromptResponse response = await _languageServer.SendRequest<ShowChoicePromptRequest>(
"powerShell/showChoicePrompt",
new ShowChoicePromptRequest
{
Expand All @@ -143,7 +144,7 @@ public async Task<IReadOnlyList<string>> PromptMultipleSelectionAsync(string mes
Message = message,
Choices = choiceDetails,
DefaultChoices = defaultChoiceIndexes?.ToArray(),
});
}).Returning<ShowChoicePromptResponse>(CancellationToken.None);

if (response.PromptCancelled)
{
Expand All @@ -160,7 +161,7 @@ public async Task<string> PromptSelectionAsync(string message, IReadOnlyList<Pro
{
ChoiceDetails[] choiceDetails = GetChoiceDetails(choices);

ShowChoicePromptResponse response = await _languageServer.SendRequest<ShowChoicePromptRequest, ShowChoicePromptResponse>(
ShowChoicePromptResponse response = await _languageServer.SendRequest<ShowChoicePromptRequest>(
"powerShell/showChoicePrompt",
new ShowChoicePromptRequest
{
Expand All @@ -169,7 +170,7 @@ public async Task<string> PromptSelectionAsync(string message, IReadOnlyList<Pro
Message = message,
Choices = choiceDetails,
DefaultChoices = defaultChoiceIndex > -1 ? new[] { defaultChoiceIndex } : null,
});
}).Returning<ShowChoicePromptResponse>(CancellationToken.None);

if (response.PromptCancelled)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using MediatR;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.PowerShell.EditorServices.Extensions.Services
Expand Down Expand Up @@ -89,27 +90,27 @@ public void SendNotification(string method, object parameters)

public Task SendRequestAsync(string method)
{
return _languageServer.SendRequest<Unit>(method);
return _languageServer.SendRequest(method).ReturningVoid(CancellationToken.None);
}

public Task SendRequestAsync<T>(string method, T parameters)
{
return _languageServer.SendRequest<T, Unit>(method, parameters);
return _languageServer.SendRequest<T>(method, parameters).ReturningVoid(CancellationToken.None);
}

public Task<TResponse> SendRequestAsync<TResponse>(string method)
{
return _languageServer.SendRequest<TResponse>(method);
return _languageServer.SendRequest(method).Returning<TResponse>(CancellationToken.None);
}

public Task<TResponse> SendRequestAsync<T, TResponse>(string method, T parameters)
{
return _languageServer.SendRequest<T, TResponse>(method, parameters);
return _languageServer.SendRequest<T>(method, parameters).Returning<TResponse>(CancellationToken.None);
}

public Task<object> SendRequestAsync(string method, object parameters)
{
return _languageServer.SendRequest<object, object>(method, parameters);
return _languageServer.SendRequest<object>(method, parameters).Returning<object>(CancellationToken.None);
}
}
}
16 changes: 8 additions & 8 deletions src/PowerShellEditorServices/Extensions/EditorFileRanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ public interface ILspFilePosition
/// <summary>
/// The line index of the position within the file.
/// </summary>
long Line { get; }
int Line { get; }

/// <summary>
/// The character offset from the line of the position.
/// </summary>
long Character { get; }
int Character { get; }
}

/// <summary>
Expand Down Expand Up @@ -260,9 +260,9 @@ public OmnisharpLspPosition(Position position)
_position = position;
}

public long Line => _position.Line;
public int Line => _position.Line;

public long Character => _position.Character;
public int Character => _position.Character;

public bool Equals(OmnisharpLspPosition other)
{
Expand Down Expand Up @@ -350,15 +350,15 @@ public FilePosition(int line, int column)
/// </summary>
public class LspFilePosition : ILspFilePosition
{
public LspFilePosition(long line, long column)
public LspFilePosition(int line, int column)
{
Line = line;
Character = column;
}

public long Line { get; }
public int Line { get; }

public long Character { get; }
public int Character { get; }
}

/// <summary>
Expand Down Expand Up @@ -455,7 +455,7 @@ public static ILspFileRange ToLspRange(this IFileRange range)
/// <returns>An equivalent 1-based file position.</returns>
public static IFilePosition ToFilePosition(this ILspFilePosition position)
{
return new FilePosition((int)position.Line + 1, (int)position.Character + 1);
return new FilePosition(position.Line + 1, position.Character + 1);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/PowerShellEditorServices/PowerShellEditorServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.3" />
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.16.0" />
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.17.0-*" />
Copy link
Contributor

@bergmeister bergmeister May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TylerLeonhardt @rjmholt
This change broke the build in the last view days because on that myget server, they also publish packages that end with 0.17.0-pullrequest, which are being used. We should use something like 0.17.0-alpha* instead.
I opened PR #1299 to fix that and adapt to the new breaking changes in its newer versions

<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
Expand All @@ -49,7 +49,7 @@
<PackageReference Include="System.Security.Principal" Version="4.3.0" />
<PackageReference Include="System.Security.Principal.Windows" Version="4.7.0" />
<PackageReference Include="UnixConsoleEcho" Version="0.1.0" />
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="0.16.0" />
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="0.17.0-*" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 12 additions & 2 deletions src/PowerShellEditorServices/Server/PsesLanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,25 @@ public async Task StartAsync()
.WithHandler<ShowHelpHandler>()
.WithHandler<ExpandAliasHandler>()
.OnInitialize(
async (languageServer, request) =>
async (languageServer, request, cancellationToken) =>
{
var serviceProvider = languageServer.Services;
var workspaceService = serviceProvider.GetService<WorkspaceService>();

// Grab the workspace path from the parameters
if (request.RootUri != null)
{
workspaceService.WorkspacePath = workspaceService.ResolveFileUri(request.RootUri).LocalPath;
workspaceService.WorkspacePath = request.RootUri.GetFileSystemPath();
}
else
{
// If RootUri isn't set, try to use the first WorkspaceFolder.
// TODO: Support multi-workspace.
foreach (var workspaceFolder in request.WorkspaceFolders)
{
workspaceService.WorkspacePath = workspaceFolder.Uri.GetFileSystemPath();
break;
}
}

// Set the working directory of the PowerShell session to the workspace path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.PowerShell.EditorServices.Services.Analysis;
using Microsoft.PowerShell.EditorServices.Services.Configuration;
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;

Expand All @@ -41,7 +42,7 @@ internal static string GetUniqueIdFromDiagnostic(Diagnostic diagnostic)
var sb = new StringBuilder(256)
.Append(diagnostic.Source ?? "?")
.Append("_")
.Append(diagnostic.Code.IsString ? diagnostic.Code.String : diagnostic.Code.Long.ToString())
.Append(diagnostic.Code?.IsString ?? true ? diagnostic.Code?.String : diagnostic.Code?.Long.ToString())
.Append("_")
.Append(diagnostic.Severity?.ToString() ?? "?")
.Append("_")
Expand Down Expand Up @@ -421,7 +422,7 @@ private void PublishScriptDiagnostics(ScriptFile scriptFile, IReadOnlyList<Scrip

_languageServer.Document.PublishDiagnostics(new PublishDiagnosticsParams
{
Uri = new Uri(scriptFile.DocumentUri),
Uri = DocumentUri.From(scriptFile.DocumentUri),
Diagnostics = new Container<Diagnostic>(diagnostics)
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public CodeLens ResolveCodeLens(CodeLens codeLens, ScriptFile scriptFile)

SymbolReference foundSymbol = _symbolsService.FindFunctionDefinitionAtLocation(
scriptFile,
(int)codeLens.Range.Start.Line + 1,
(int)codeLens.Range.Start.Character + 1);
codeLens.Range.Start.Line + 1,
codeLens.Range.Start.Character + 1);

List<SymbolReference> referencesResult = _symbolsService.FindReferencesOfSymbol(
foundSymbol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ public async Task<SetBreakpointsResponse> Handle(SetBreakpointsArguments request
BreakpointDetails[] breakpointDetails = request.Breakpoints
.Select((srcBreakpoint) => BreakpointDetails.Create(
scriptFile.FilePath,
(int)srcBreakpoint.Line,
(int?)srcBreakpoint.Column,
srcBreakpoint.Line,
srcBreakpoint.Column,
srcBreakpoint.Condition,
srcBreakpoint.HitCondition,
srcBreakpoint.LogMessage))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ConfigurationDoneHandler(
_workspaceService = workspaceService;
}

public async Task<ConfigurationDoneResponse> Handle(ConfigurationDoneArguments request, CancellationToken cancellationToken)
public Task<ConfigurationDoneResponse> Handle(ConfigurationDoneArguments request, CancellationToken cancellationToken)
{
_debugService.IsClientAttached = true;

Expand Down Expand Up @@ -90,7 +90,7 @@ public async Task<ConfigurationDoneResponse> Handle(ConfigurationDoneArguments r
}
}

return new ConfigurationDoneResponse();
return Task.FromResult(new ConfigurationDoneResponse());
}

private async Task LaunchScriptAsync(string scriptToLaunch)
Expand Down
Loading