Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Take a look at method <code>ICSharpCode.NRefactory.CSharp.CodeCompletion.CreateEngine</code>. You need to create an instance of <code>CSharpCompletionEngine</code> and pass in the correct document and the resolvers. I managed to get it working for CTRL+Space compltition scenario. However I am having troubles with references to types that are in other namespaces. It looks like <code>CSharpTypeResolveContext</code> does not take into account the using namespace statements - If I resolve the references with <code>CSharpAstResolver</code>, they are resolved OK, but I am unable to correctly use this resolver in code completition scenario...</p> <p><strong>UPDATE #1:</strong></p> <p>I've just managed to get the working by obtaining resolver from unresolved fail.</p> <p>Here is the snippet:</p> <pre><code>var mb = new DefaultCompletionContextProvider(doc, unresolvedFile); var resolver3 = unresolvedFile.GetResolver(cmp, loc); // get the resolver from unresolvedFile var engine = new CSharpCompletionEngine(doc, mb, new CodeCompletionBugTests.TestFactory(resolver3), pctx, resolver3.CurrentTypeResolveContext ); </code></pre> <p><strong>Update #2:</strong></p> <p>Here is the complete method. It references classes from unit test projects, sou you would need to reference/copy them into your project:</p> <pre><code>public static IEnumerable&lt;ICompletionData&gt; DoCodeComplete(string editorText, int offset) // not the best way to put in the whole string every time { var doc = new ReadOnlyDocument(editorText); var location = doc.GetLocation(offset); string parsedText = editorText; // TODO: Why there are different values in test cases? var syntaxTree = new CSharpParser().Parse(parsedText, "program.cs"); syntaxTree.Freeze(); var unresolvedFile = syntaxTree.ToTypeSystem(); var mb = new DefaultCompletionContextProvider(doc, unresolvedFile); IProjectContent pctx = new CSharpProjectContent(); var refs = new List&lt;IUnresolvedAssembly&gt; { mscorlib.Value, systemCore.Value, systemAssembly.Value}; pctx = pctx.AddAssemblyReferences(refs); pctx = pctx.AddOrUpdateFiles(unresolvedFile); var cmp = pctx.CreateCompilation(); var resolver3 = unresolvedFile.GetResolver(cmp, location); var engine = new CSharpCompletionEngine(doc, mb, new CodeCompletionBugTests.TestFactory(resolver3), pctx, resolver3.CurrentTypeResolveContext ); engine.EolMarker = Environment.NewLine; engine.FormattingPolicy = FormattingOptionsFactory.CreateMono(); var data = engine.GetCompletionData(offset, controlSpace: false); return data; } </code></pre> <p>}</p> <p>Hope it helps, Matra</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload