-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathRimworlXMLCompletionContextProvider.cs
More file actions
78 lines (67 loc) · 3.26 KB
/
RimworlXMLCompletionContextProvider.cs
File metadata and controls
78 lines (67 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using JetBrains.Annotations;
using JetBrains.Application.Parts;
using JetBrains.DocumentModel;
using JetBrains.ReSharper.Feature.Services.CodeCompletion.Impl;
using JetBrains.ReSharper.Feature.Services.CodeCompletion.Infrastructure;
using JetBrains.ReSharper.Features.Intellisense.CodeCompletion.Xml;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Resolve;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.ReSharper.Psi.Xml.Tree;
// This is a copied/modified version of some CompletionContext thing from Jetbrains because the default completion
// context doesn't provide for certain things that we need to get the symbol scope or the file or something like that
// in XML contexts
namespace ReSharperPlugin.RimworldDev
{
public class RimworldXmlCodeCompletionContext : SpecificCodeCompletionContext
{
public IXmlFile File;
[CanBeNull]
public ITreeNode TreeNode;
public TextLookupRanges Ranges { get; private set; }
public RimworldXmlCodeCompletionContext(
CodeCompletionContext context,
IXmlFile file,
ITreeNode treeNode,
TextLookupRanges ranges)
: base(context)
{
File = file;
TreeNode = treeNode;
Ranges = ranges;
}
public override string ContextId => nameof (XmlCodeCompletionContext);
}
[IntellisensePart(Instantiation.DemandAnyThreadSafe)]
public class RimworlXMLCompletionContextProvider: XmlCodeCompletionContextProvider
{
public override bool IsApplicable(CodeCompletionContext context)
{
return true;
}
public override ISpecificCodeCompletionContext GetCompletionContext(CodeCompletionContext context)
{
if (context.File is not IXmlFile xmlFile) return null;
XmlReparsedCodeCompletionContext unterminatedContext = this.CreateUnterminatedContext(xmlFile, context);
if (unterminatedContext == null)
return (ISpecificCodeCompletionContext) null;
unterminatedContext.Init();
IReference reference = unterminatedContext.Reference;
ITreeNode treeNode = unterminatedContext.TreeNode;
if (treeNode == null)
return (ISpecificCodeCompletionContext) null;
TreeTextRange treeRange = reference == null ? XmlCodeCompletionContextProvider.GetElementRange(treeNode) : reference.GetTreeTextRange();
DocumentRange documentRange = unterminatedContext.ToDocumentRange(treeRange);
if (!documentRange.IsValid())
return (ISpecificCodeCompletionContext) null;
ref DocumentRange local1 = ref documentRange;
DocumentOffset caretDocumentOffset = context.EffectiveCaretDocumentOffset;
ref DocumentOffset local2 = ref caretDocumentOffset;
if (!local1.Contains(in local2))
return (ISpecificCodeCompletionContext) null;
TextLookupRanges textLookupRanges = CodeCompletionContextProviderBase.GetTextLookupRanges(context, documentRange);
return new RimworldXmlCodeCompletionContext(context, xmlFile,
xmlFile.FindNodeAt(unterminatedContext.Range), textLookupRanges);
}
}
}