Skip to content
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

WIP: New completion service #884

Closed
18 changes: 18 additions & 0 deletions src/OmniSharp.Abstractions/Models/FileBasedRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.IO;

namespace OmniSharp.Models
{
public class FileBasedRequest : IRequest
{
private string _fileName;

/// <summary>
/// The name of the file this request is based on.
/// </summary>
public string FileName
{
get => _fileName?.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
set => _fileName = value;
}
}
}
16 changes: 1 addition & 15 deletions src/OmniSharp.Abstractions/Models/Request.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;

namespace OmniSharp.Models
{
public class Request : IRequest
public class Request : FileBasedRequest
{
private string _fileName;

[JsonConverter(typeof(ZeroBasedIndexConverter))]
public int Line { get; set; }
[JsonConverter(typeof(ZeroBasedIndexConverter))]
public int Column { get; set; }
public string Buffer { get; set; }
public IEnumerable<LinePositionSpanTextChange> Changes { get; set; }
public string FileName
{
get
{
return _fileName?.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
}
set
{
_fileName = value;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace OmniSharp.Models.V2.Completion
{
public class CharacterSetModificationRule
{
/// <summary>
/// The kind of modification.
/// </summary>
[JsonConverter(typeof(StringEnumConverter), /*camelCaseText*/ true)]
public CharacterSetModificationRuleKind Kind { get; set; }

/// <summary>
/// One or more characters.
/// </summary>
public char[] Characters { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace OmniSharp.Models.V2.Completion
{
public enum CharacterSetModificationRuleKind
{
Add,
Remove,
Replace
}
}
22 changes: 22 additions & 0 deletions src/OmniSharp.Abstractions/Models/v2/Completion/CompletionItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace OmniSharp.Models.V2.Completion
{
public class CompletionItem
{
public string DisplayText { get; set; }
public string Kind { get; set; }
public string FilterText { get; set; }
public string SortText { get; set; }

/// <summary>
/// Rules that modify the set of characters that can be typed to cause the
/// selected item to be commited.
/// </summary>
public CharacterSetModificationRule[] CommitCharacterRules { get; set; }

// These properties must be resolved via the '/v2/completionItem/resolve'
// end point before they are available.
public string Description { get; set; }
public TextEdit TextEdit { get; set; }
public TextEdit[] AdditionalTextEdits { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using OmniSharp.Mef;

namespace OmniSharp.Models.V2.Completion
{
[OmniSharpEndpoint(OmniSharpEndpoints.V2.CompletionItemResolve, typeof(CompletionItemResolveRequest), typeof(CompletionItemResolveResponse))]
public class CompletionItemResolveRequest : FileBasedRequest
{
/// <summary>
/// Zero-based index of the completion item to resolve within the list of items returned
/// by the last <see cref="CompletionResponse"/>.
/// </summary>
public int ItemIndex { get; set; }

/// <summary>
/// The display text of the completion item to resolve. If set, this is used to help verify
/// that the correct completion item is resolved.
/// </summary>
public string DisplayText { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OmniSharp.Models.V2.Completion
{
public class CompletionItemResolveResponse
{
public CompletionItem Item { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using OmniSharp.Mef;

namespace OmniSharp.Models.V2.Completion
{
[OmniSharpEndpoint(OmniSharpEndpoints.V2.Completion, typeof(CompletionRequest), typeof(CompletionResponse))]
public class CompletionRequest : FileBasedRequest
{
/// <summary>
/// The zero-based position in the file where completion is requested.
/// </summary>
public int Position { get; set; }

/// <summary>
/// The action that started completion.
/// </summary>
public CompletionTrigger Trigger { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace OmniSharp.Models.V2.Completion
{
public class CompletionResponse
{
// Note: We use an expression-bodied property rather than a getter-only auto-property
// to ensure that a new instance is created every time, since this class is mutable.
public static CompletionResponse Empty => new CompletionResponse();

/// <summary>
/// The default set of typed characters that cause a completion item to be committed.
/// </summary>
public char[] DefaultCommitCharacters { get; set; }

/// <summary>
/// Returns true if the completion list is "suggestion mode", meaning that it should not
/// commit aggressively on characters like ' '.
/// </summary>
public bool IsSuggestionMode { get; set; }

/// <summary>
/// The completion items to present to the user.
/// </summary>
public CompletionItem[] Items { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace OmniSharp.Models.V2.Completion
{
public class CompletionTrigger
{
/// <summary>
/// The action that started completion.
/// </summary>
[JsonConverter(typeof(StringEnumConverter), /*camelCaseText*/ true)]
public CompletionTriggerKind Kind { get; set; }

/// <summary>
/// The character associated with the triggering action.
/// </summary>
public string Character { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace OmniSharp.Models.V2.Completion
{
public enum CompletionTriggerKind
{
Invoke,
Insertion,
Deletion
}
}
8 changes: 8 additions & 0 deletions src/OmniSharp.Abstractions/Models/v2/TextEdit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OmniSharp.Models.V2
{
public class TextEdit
{
public Range Range { get; set; }
public string NewText { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/OmniSharp.Abstractions/OmniSharpEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public static class OmniSharpEndpoints

public static class V2
{
public const string Completion = "/v2/completion";
public const string CompletionItemResolve = "/v2/completionItem/resolve";

public const string GetCodeActions = "/v2/getcodeactions";
public const string RunCodeAction = "/v2/runcodeaction";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
using OmniSharp.Options;
using OmniSharp.Roslyn.CSharp.Services.Documentation;

namespace OmniSharp.Roslyn.CSharp.Services.Intellisense
namespace OmniSharp.Roslyn.CSharp.Services.IntelliSense
{
[OmniSharpHandler(OmniSharpEndpoints.AutoComplete, LanguageNames.CSharp)]
public class IntellisenseService : IRequestHandler<AutoCompleteRequest, IEnumerable<AutoCompleteResponse>>
public class AutoCompleteService : IRequestHandler<AutoCompleteRequest, IEnumerable<AutoCompleteResponse>>
{
private readonly OmniSharpWorkspace _workspace;
private readonly FormattingOptions _formattingOptions;

[ImportingConstructor]
public IntellisenseService(OmniSharpWorkspace workspace, FormattingOptions formattingOptions)
public AutoCompleteService(OmniSharpWorkspace workspace, FormattingOptions formattingOptions)
{
_workspace = workspace;
_formattingOptions = formattingOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Microsoft.CodeAnalysis.Completion;
using OmniSharp.Utilities;

namespace OmniSharp.Roslyn.CSharp.Services.Intellisense
namespace OmniSharp.Roslyn.CSharp.Services.IntelliSense
{
internal static class CompletionItemExtensions
{
Expand Down
Loading