|
|
@ -196,14 +196,18 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion |
|
|
|
return new CecilLoader().LoadAssemblyFile(typeof(System.ComponentModel.BrowsableAttribute).Assembly.Location); |
|
|
|
return new CecilLoader().LoadAssemblyFile(typeof(System.ComponentModel.BrowsableAttribute).Assembly.Location); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
static CompletionDataList CreateProvider(string text, bool isCtrlSpace) |
|
|
|
public static CSharpCompletionEngine CreateEngine(string text, out int cursorPosition, params IUnresolvedAssembly[] references) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string parsedText; |
|
|
|
string parsedText; |
|
|
|
string editorText; |
|
|
|
string editorText; |
|
|
|
int cursorPosition = text.IndexOf('$'); |
|
|
|
cursorPosition = text.IndexOf('$'); |
|
|
|
int endPos = text.IndexOf('$', cursorPosition + 1); |
|
|
|
int endPos = text.IndexOf('$', cursorPosition + 1); |
|
|
|
if (endPos == -1) { |
|
|
|
if (endPos == -1) { |
|
|
|
|
|
|
|
if (cursorPosition < 0) { |
|
|
|
|
|
|
|
parsedText = editorText = text; |
|
|
|
|
|
|
|
} else { |
|
|
|
parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1); |
|
|
|
parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
parsedText = text.Substring(0, cursorPosition) + new string(' ', endPos - cursorPosition) + text.Substring(endPos + 1); |
|
|
|
parsedText = text.Substring(0, cursorPosition) + new string(' ', endPos - cursorPosition) + text.Substring(endPos + 1); |
|
|
|
editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1); |
|
|
|
editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1); |
|
|
@ -212,7 +216,11 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion |
|
|
|
var doc = new ReadOnlyDocument(editorText); |
|
|
|
var doc = new ReadOnlyDocument(editorText); |
|
|
|
|
|
|
|
|
|
|
|
IProjectContent pctx = new CSharpProjectContent(); |
|
|
|
IProjectContent pctx = new CSharpProjectContent(); |
|
|
|
pctx = pctx.AddAssemblyReferences(new [] { CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore, SystemAssembly }); |
|
|
|
var refs = new List<IUnresolvedAssembly> { CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore, SystemAssembly }; |
|
|
|
|
|
|
|
if (references != null) |
|
|
|
|
|
|
|
refs.AddRange (references); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pctx = pctx.AddAssemblyReferences(refs); |
|
|
|
|
|
|
|
|
|
|
|
var compilationUnit = new CSharpParser().Parse(parsedText, "program.cs"); |
|
|
|
var compilationUnit = new CSharpParser().Parse(parsedText, "program.cs"); |
|
|
|
compilationUnit.Freeze(); |
|
|
|
compilationUnit.Freeze(); |
|
|
@ -221,12 +229,11 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion |
|
|
|
pctx = pctx.UpdateProjectContent(null, parsedFile); |
|
|
|
pctx = pctx.UpdateProjectContent(null, parsedFile); |
|
|
|
|
|
|
|
|
|
|
|
var cmp = pctx.CreateCompilation(); |
|
|
|
var cmp = pctx.CreateCompilation(); |
|
|
|
var loc = doc.GetLocation(cursorPosition); |
|
|
|
var loc = cursorPosition > 0 ? doc.GetLocation(cursorPosition) : new TextLocation (1, 1); |
|
|
|
|
|
|
|
|
|
|
|
var rctx = new CSharpTypeResolveContext(cmp.MainAssembly); |
|
|
|
var rctx = new CSharpTypeResolveContext(cmp.MainAssembly); |
|
|
|
rctx = rctx.WithUsingScope(parsedFile.GetUsingScope(loc).Resolve(cmp)); |
|
|
|
rctx = rctx.WithUsingScope(parsedFile.GetUsingScope(loc).Resolve(cmp)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var curDef = parsedFile.GetInnermostTypeDefinition(loc); |
|
|
|
var curDef = parsedFile.GetInnermostTypeDefinition(loc); |
|
|
|
if (curDef != null) { |
|
|
|
if (curDef != null) { |
|
|
|
var resolvedDef = curDef.Resolve(rctx).GetDefinition(); |
|
|
|
var resolvedDef = curDef.Resolve(rctx).GetDefinition(); |
|
|
@ -241,7 +248,13 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion |
|
|
|
|
|
|
|
|
|
|
|
engine.EolMarker = Environment.NewLine; |
|
|
|
engine.EolMarker = Environment.NewLine; |
|
|
|
engine.FormattingPolicy = FormattingOptionsFactory.CreateMono(); |
|
|
|
engine.FormattingPolicy = FormattingOptionsFactory.CreateMono(); |
|
|
|
|
|
|
|
return engine; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static CompletionDataList CreateProvider(string text, bool isCtrlSpace, params IUnresolvedAssembly[] references) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int cursorPosition; |
|
|
|
|
|
|
|
var engine = CreateEngine(text, out cursorPosition, references); |
|
|
|
var data = engine.GetCompletionData (cursorPosition, isCtrlSpace); |
|
|
|
var data = engine.GetCompletionData (cursorPosition, isCtrlSpace); |
|
|
|
|
|
|
|
|
|
|
|
return new CompletionDataList () { |
|
|
|
return new CompletionDataList () { |
|
|
|