Created
February 20, 2020 14:22
-
-
Save warrenbuckley/c88b8c5c9cf91f9857ceff8b07c2ac43 to your computer and use it in GitHub Desktop.
Trying to get autocompletion on a Razor .cshtml view with Roslyn's CompletionService
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [HttpPost] | |
| public string FetchCompletions(RazorCode model) | |
| { | |
| var host = new System.Web.Razor.RazorEngineHost(new CSharpRazorCodeLanguage()); | |
| var templateEngine = new System.Web.Razor.RazorTemplateEngine(host); | |
| var compiledCode = templateEngine.GenerateCode(new StringReader(model.Code)); | |
| var parsed = templateEngine.ParseTemplate(new StringReader(model.Code)); | |
| // Cannot convert from 'System.Web.Razor.Parser.SyntaxTree.Block' to 'Microsoft.CodeAnalysis.Document' | |
| var completionService = Microsoft.CodeAnalysis.Completion.CompletionService.GetService(compiledCode.Document); | |
| var completions = completionService.GetCompletionsAsync(compiledCode.Document, 1); | |
| return "hello warren"; | |
| } |
Hi Warren, Did you find the solution?
@muratalalmis no not from memory - do you have an answer to the problem?
I couldn't find a solution with this way but I saw a solution when I'm inspecting the vscode's C# extension. It was using the omnisharp (http://prntscr.com/vk5aw0)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note
The above code is NOT working & this is what I need some help & advice on.