static CompletionDataList CreateProvider (string text, bool isCtrlSpace)
{
string parsedText;
string editorText;
int cursorPosition = text.IndexOf ('$');
int endPos = text.IndexOf ('$', cursorPosition + 1);
if (endPos == -1)
parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1);
else {
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);
cursorPosition = endPos - 1;
}
TestWorkbenchWindow tww = new TestWorkbenchWindow ();
TestViewContent sev = new TestViewContent ();
DotNetProject project = new DotNetAssemblyProject ("C#");
project.FileName = GetTempFile (".csproj");
string file = GetTempFile (".cs");
project.AddFile (file);
ProjectDomService.Load (project);
ProjectDom dom = ProjectDomService.GetProjectDom (project);
dom.ForceUpdate (true);
ProjectDomService.Parse (project, file, delegate { return parsedText; });
ProjectDomService.Parse (project, file, delegate { return parsedText; });
sev.Project = project;
sev.ContentName = file;
sev.Text = editorText;
sev.CursorPosition = cursorPosition;
tww.ViewContent = sev;
Document doc = new Document (tww);
doc.ParsedDocument = new NRefactoryParser ().Parse (null, sev.ContentName, parsedText);
foreach (var e in doc.ParsedDocument.Errors)
Console.WriteLine (e);
CSharpTextEditorCompletion textEditorCompletion = new CSharpTextEditorCompletion (doc);
int triggerWordLength = 1;
CodeCompletionContext ctx = new CodeCompletionContext ();
ctx.TriggerOffset = sev.CursorPosition;
int line, column;
sev.GetLineColumnFromPosition (sev.CursorPosition, out line, out column);
ctx.TriggerLine = line;
ctx.TriggerLineOffset = column - 1;
if (isCtrlSpace)
return textEditorCompletion.CodeCompletionCommand (ctx) as CompletionDataList;
return textEditorCompletion.HandleCodeCompletion (ctx, editorText[cursorPosition - 1] , ref triggerWordLength) as CompletionDataList;
}