Skip to content

Commit

Permalink
Merge pull request #1420 from OmniSharp/feature/typelookup-constant
Browse files Browse the repository at this point in the history
 include constant values in TypeLookup
  • Loading branch information
david-driscoll authored Mar 16, 2019
2 parents d94de60 + 1804482 commit 0daf4ec
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
All changes to the project will be documented in this file.

## [1.32.12] - not released yet
* Include constant values in `/typelookup` responses ([omnisharp-vscode#2857](https://github.com/OmniSharp/omnisharp-vscode/issues/2857), PR: [#1420](https://github.com/OmniSharp/omnisharp-roslyn/pull/1420))

## [1.32.11] - 2019-02-27
* Updated to Roslyn `3.0.0-beta4-19126-05` to match VS 16.0p4 ([#1413](https://github.com/OmniSharp/omnisharp-roslyn/issues/1413), PR: [#1414](https://github.com/OmniSharp/omnisharp-roslyn/pull/1414))
* Added support for reading C# 8.0 `NullableContextOptions` from csproj files ([#1396](https://github.com/OmniSharp/omnisharp-roslyn/issues/1396), PR: [#1404](https://github.com/OmniSharp/omnisharp-roslyn/pull/1404))
Expand Down
11 changes: 10 additions & 1 deletion src/OmniSharp.Roslyn.CSharp/Services/Types/TypeLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public class TypeLookupService : IRequestHandler<TypeLookupRequest, TypeLookupRe
WithMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.None).
WithMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers);

// default from symbol.ToMinimalDisplayString + IncludeConstantValue
private static readonly SymbolDisplayFormat MinimalFormat = SymbolDisplayFormat.MinimallyQualifiedFormat.WithMemberOptions(
SymbolDisplayMemberOptions.IncludeParameters |
SymbolDisplayMemberOptions.IncludeType |
SymbolDisplayMemberOptions.IncludeRef |
SymbolDisplayMemberOptions.IncludeContainingType |
SymbolDisplayMemberOptions.IncludeConstantValue
);

[ImportingConstructor]
public TypeLookupService(OmniSharpWorkspace workspace, FormattingOptions formattingOptions)
{
Expand All @@ -41,7 +50,7 @@ public async Task<TypeLookupResponse> Handle(TypeLookupRequest request)
{
response.Type = symbol.Kind == SymbolKind.NamedType ?
symbol.ToDisplayString(DefaultFormat) :
symbol.ToMinimalDisplayString(semanticModel, position);
symbol.ToMinimalDisplayString(semanticModel, position, MinimalFormat);

if (request.IncludeDocumentation)
{
Expand Down
23 changes: 23 additions & 0 deletions tests/OmniSharp.Roslyn.CSharp.Tests/TypeLookupFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,22 @@ public Foo() {
public IDictionary<string, IEnumerable<int>> SomeDict { get; }
public void Compute(int index = 2) { }
private const int foo = 1;
}
}
namespace Bar2 {
class Foo2 {
}
}
namespace Bar3 {
enum Foo3 {
Val1 = 1,
Val2
}
}
");

[Fact]
Expand Down Expand Up @@ -234,6 +243,20 @@ public async Task DisplayFormatFor_FieldSymbol()
Assert.Equal("Foo2 Foo._someField", response.Type);
}

[Fact]
public async Task DisplayFormatFor_FieldSymbol_WithConstantValue()
{
var response = await GetTypeLookUpResponse(line: 19, column: 41);
Assert.Equal("int Foo.foo = 1", response.Type);
}

[Fact]
public async Task DisplayFormatFor_EnumValue()
{
var response = await GetTypeLookUpResponse(line: 31, column: 23);
Assert.Equal("Foo3.Val2 = 2", response.Type);
}

[Fact]
public async Task DisplayFormatFor_PropertySymbol()
{
Expand Down

0 comments on commit 0daf4ec

Please sign in to comment.