internal static IParameterDataProvider CreateProvider (string text) { 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); 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); CSharpTextEditorCompletion textEditorCompletion = new CSharpTextEditorCompletion (doc); 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; IParameterDataProvider result = textEditorCompletion.HandleParameterCompletion (ctx, editorText[cursorPosition - 1]); ProjectDomService.Unload (project); return result; }
public CompletionDataCollector (CSharpTextEditorCompletion editorCompletion, ProjectDom dom, CompletionDataList completionList, ICompilationUnit unit, IType declaringType, DomLocation location) { this.editorCompletion = editorCompletion; this.CompletionList = completionList; this.unit = unit; this.dom = dom; this.FullyQualify = false; // this.location = location; this.declaringType = declaringType; // completionList.AddKeyHandler (new NegateKeyHandler ()); // Get a list of all namespaces in scope if (unit != null) { foreach (IUsing u in unit.Usings) { if (!u.IsFromNamespace || u.Region.Contains (location)) { foreach (string ns in u.Namespaces) namespacesInScope.Add (ns); } } } }
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; }