Skip to content

Commit 56c7b12

Browse files
wip /resolve route resolution
1 parent f0b65f1 commit 56c7b12

20 files changed

+486
-22
lines changed

LSP.sln

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio 15
3-
VisualStudioVersion = 15.0.27004.2009
3+
VisualStudioVersion = 15.0.27130.2003
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D764E024-3D3F-4112-B932-2DB722A1BACC}"
6+
ProjectSection(SolutionItems) = preProject
7+
src\Directory.Build.props = src\Directory.Build.props
8+
EndProjectSection
69
EndProject
710
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2F323ED5-EBF8-45E1-B9D3-C014561B3DDA}"
811
EndProject

src/Protocol/Document/IDocumentLinkHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ public static partial class DocumentNames
1313
}
1414

1515
[Parallel, Method(DocumentLink)]
16-
public interface IDocumentLinkHandler : IRequestHandler<DocumentLinkParams, DocumentLink>, IRegistration<DocumentLinkRegistrationOptions>, ICapability<DocumentLinkCapability> { }
16+
public interface IDocumentLinkHandler : IRequestHandler<DocumentLinkParams, DocumentLinkContainer>, IRegistration<DocumentLinkRegistrationOptions>, ICapability<DocumentLinkCapability> { }
1717
}

src/Protocol/Models/CodeLens.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
1212
/// A code lens is _unresolved_ when no command is associated to it. For performance
1313
/// reasons the creation of a code lens and resolving should be done in two stages.
1414
/// </summary>
15-
public class CodeLens
15+
public class CodeLens : ICanBeResolved
1616
{
1717
/// <summary>
1818
/// The range in which this code lens is valid. Should only span a single line.

src/Protocol/Models/CodeLensContainer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.Collections.ObjectModel;
33
using System.Linq;
44

@@ -33,4 +33,4 @@ public static implicit operator CodeLensContainer(List<CodeLens> items)
3333
return new CodeLensContainer(items);
3434
}
3535
}
36-
}
36+
}

src/Protocol/Models/CompletionItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
77
{
8-
public class CompletionItem
8+
public class CompletionItem : ICanBeResolved
99
{
1010
/// <summary>
1111
/// The label of this completion item. By default

src/Protocol/Models/ContainerBase.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using System.Collections;
1+
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using Newtonsoft.Json;
45
using Newtonsoft.Json.Serialization;
56

67
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
78
{
8-
public abstract class ContainerBase<T> : IEnumerable<T>
9+
public abstract class ContainerBase<T> : IEnumerable<T>, IEquatable<ContainerBase<T>>
910
{
1011
private readonly IEnumerable<T> _items;
1112

@@ -14,14 +15,40 @@ public ContainerBase(IEnumerable<T> items)
1415
_items = items;
1516
}
1617

18+
public override bool Equals(object obj)
19+
{
20+
return Equals(obj as ContainerBase<T>);
21+
}
22+
23+
public bool Equals(ContainerBase<T> other)
24+
{
25+
return other != null &&
26+
EqualityComparer<IEnumerable<T>>.Default.Equals(_items, other._items);
27+
}
28+
1729
public IEnumerator<T> GetEnumerator()
1830
{
1931
return _items.GetEnumerator();
2032
}
2133

34+
public override int GetHashCode()
35+
{
36+
return -566117206 + EqualityComparer<IEnumerable<T>>.Default.GetHashCode(_items);
37+
}
38+
2239
IEnumerator IEnumerable.GetEnumerator()
2340
{
2441
return GetEnumerator();
2542
}
43+
44+
public static bool operator ==(ContainerBase<T> base1, ContainerBase<T> base2)
45+
{
46+
return EqualityComparer<ContainerBase<T>>.Default.Equals(base1, base2);
47+
}
48+
49+
public static bool operator !=(ContainerBase<T> base1, ContainerBase<T> base2)
50+
{
51+
return !(base1 == base2);
52+
}
2653
}
2754
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
3+
using System.Linq;
4+
5+
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
6+
{
7+
public class DocumentLinkContainer : Container<DocumentLink>
8+
{
9+
public DocumentLinkContainer() : this(Enumerable.Empty<DocumentLink>())
10+
{
11+
}
12+
13+
public DocumentLinkContainer(IEnumerable<DocumentLink> items) : base(items)
14+
{
15+
}
16+
17+
public DocumentLinkContainer(params DocumentLink[] items) : base(items)
18+
{
19+
}
20+
21+
public static implicit operator DocumentLinkContainer(DocumentLink[] items)
22+
{
23+
return new DocumentLinkContainer(items);
24+
}
25+
26+
public static implicit operator DocumentLinkContainer(Collection<DocumentLink> items)
27+
{
28+
return new DocumentLinkContainer(items);
29+
}
30+
31+
public static implicit operator DocumentLinkContainer(List<DocumentLink> items)
32+
{
33+
return new DocumentLinkContainer(items);
34+
}
35+
}
36+
}

src/Protocol/Models/ICanBeResolved.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Newtonsoft.Json.Linq;
2+
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
3+
4+
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
5+
{
6+
/// <summary>
7+
/// Common interface for types that support resolution.
8+
/// </summary>
9+
public interface ICanBeResolved
10+
{
11+
/// <summary>
12+
/// A data entry field that is preserved for resolve requests
13+
/// </summary>
14+
[Optional]
15+
JToken Data { get; set; }
16+
}
17+
}

src/Protocol/Models/Location.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using System;
1+
using System;
2+
using System.Collections.Generic;
23
using Newtonsoft.Json;
34
using Newtonsoft.Json.Serialization;
45

56
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
67
{
7-
public class Location
8+
public class Location : IEquatable<Location>
89
{
910
/// <summary>
1011
/// The uri of the document
@@ -15,5 +16,35 @@ public class Location
1516
/// The range in side the document given by the uri
1617
/// </summary>
1718
public Range Range { get; set; }
19+
20+
public override bool Equals(object obj)
21+
{
22+
return Equals(obj as Location);
23+
}
24+
25+
public bool Equals(Location other)
26+
{
27+
return other != null &&
28+
EqualityComparer<Uri>.Default.Equals(Uri, other.Uri) &&
29+
EqualityComparer<Range>.Default.Equals(Range, other.Range);
30+
}
31+
32+
public override int GetHashCode()
33+
{
34+
var hashCode = 1486144663;
35+
hashCode = hashCode * -1521134295 + EqualityComparer<Uri>.Default.GetHashCode(Uri);
36+
hashCode = hashCode * -1521134295 + EqualityComparer<Range>.Default.GetHashCode(Range);
37+
return hashCode;
38+
}
39+
40+
public static bool operator ==(Location location1, Location location2)
41+
{
42+
return EqualityComparer<Location>.Default.Equals(location1, location2);
43+
}
44+
45+
public static bool operator !=(Location location1, Location location2)
46+
{
47+
return !(location1 == location2);
48+
}
1849
}
1950
}

src/Protocol/Models/Position.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
using Newtonsoft.Json;
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
24
using Newtonsoft.Json.Serialization;
35

46
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
57
{
6-
public class Position
8+
public class Position : IEquatable<Position>
79
{
810
public Position()
911
{
@@ -24,5 +26,35 @@ public Position(long line, long character)
2426
/// Character offset on a line in a document (zero-based).
2527
/// </summary>
2628
public long Character { get; set; }
29+
30+
public override bool Equals(object obj)
31+
{
32+
return Equals(obj as Position);
33+
}
34+
35+
public bool Equals(Position other)
36+
{
37+
return other != null &&
38+
Line == other.Line &&
39+
Character == other.Character;
40+
}
41+
42+
public override int GetHashCode()
43+
{
44+
var hashCode = 1927683087;
45+
hashCode = hashCode * -1521134295 + Line.GetHashCode();
46+
hashCode = hashCode * -1521134295 + Character.GetHashCode();
47+
return hashCode;
48+
}
49+
50+
public static bool operator ==(Position position1, Position position2)
51+
{
52+
return EqualityComparer<Position>.Default.Equals(position1, position2);
53+
}
54+
55+
public static bool operator !=(Position position1, Position position2)
56+
{
57+
return !(position1 == position2);
58+
}
2759
}
2860
}

0 commit comments

Comments
 (0)