diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2016-07-29 13:52:11 +0300 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2016-07-29 13:52:11 +0300 |
commit | 6177157a5362b53d263ad23b539baf6382d1f0e3 (patch) | |
tree | 7439dc82b6c1dffafd542d13e7811bd00cc2ce29 /main/src/addins/MonoDevelop.DocFood | |
parent | 9850bcd282186d9a9c9e68160c6d62ac681dae21 (diff) |
Fixed 'Bug 42591 - XS generates documentation for preprocessor
directives.'.
Note that WithFrozenPartialSemanticAsync is a < 5ms operation which
gives the current, but maybe not 100% correct semantic. So it's not
blocking the UI thread.
(Which isn't needed since it's more or less an AST operation and the
AST is always up2date there)
Diffstat (limited to 'main/src/addins/MonoDevelop.DocFood')
-rw-r--r-- | main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood.csproj | 8 | ||||
-rw-r--r-- | main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood/DocFoodTextEditorExtension.cs | 18 |
2 files changed, 17 insertions, 9 deletions
diff --git a/main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood.csproj b/main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood.csproj index 89dad2b139..46e82424b6 100644 --- a/main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood.csproj +++ b/main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood.csproj @@ -20,11 +20,6 @@ <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <Externalconsole>True</Externalconsole> - <CustomCommands> - <CustomCommands> - <Command type="Execute" command="../../../main/build/bin/MonoDevelop.exe" /> - </CustomCommands> - </CustomCommands> <NoWarn>1591;1573</NoWarn> <DocumentationFile>..\..\..\build\AddIns\BackendBindings\MonoDevelop.DocFood.xml</DocumentationFile> </PropertyGroup> @@ -69,6 +64,9 @@ <HintPath>..\..\..\external\roslyn\Binaries\Release\Microsoft.CodeAnalysis.CSharp.dll</HintPath> <Private>False</Private> </Reference> + <Reference Include="Microsoft.CodeAnalysis.Workspaces"> + <HintPath>..\..\..\build\bin\Microsoft.CodeAnalysis.Workspaces.dll</HintPath> + </Reference> </ItemGroup> <ItemGroup> <Compile Include="AssemblyInfo.cs" /> diff --git a/main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood/DocFoodTextEditorExtension.cs b/main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood/DocFoodTextEditorExtension.cs index 7ccb5b775d..16a4d01097 100644 --- a/main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood/DocFoodTextEditorExtension.cs +++ b/main/src/addins/MonoDevelop.DocFood/MonoDevelop.DocFood/DocFoodTextEditorExtension.cs @@ -24,11 +24,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; +using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; +using MonoDevelop.CSharp.Completion; using MonoDevelop.Ide.Editor; using MonoDevelop.Ide.Editor.Extension; +using System.Threading; namespace MonoDevelop.DocFood { @@ -72,9 +75,10 @@ namespace MonoDevelop.DocFood if (l != null && Editor.GetTextAt (l).TrimStart ().StartsWith ("///", StringComparison.Ordinal)) return base.KeyPress (descriptor); - var member = GetMemberToDocument (); - if (member == null) + var memberTask = GetMemberToDocument (); + if (!memberTask.Wait (250) || memberTask.Result == null) return base.KeyPress (descriptor); + var member = memberTask.Result; string documentation = GenerateDocumentation (member, Editor.GetLineIndent (line)); if (string.IsNullOrEmpty (documentation)) @@ -156,12 +160,14 @@ namespace MonoDevelop.DocFood return true; } - ISymbol GetMemberToDocument () + async Task<ISymbol> GetMemberToDocument (CancellationToken cancellationToken = default(CancellationToken)) { var parsedDocument = DocumentContext.ParsedDocument; if (parsedDocument == null) return null; - var semanticModel = parsedDocument.GetAst<SemanticModel> (); + + var partialDoc = await CSharpCompletionTextEditorExtension.WithFrozenPartialSemanticsAsync (DocumentContext.AnalysisDocument, cancellationToken).ConfigureAwait (false); + var semanticModel = await partialDoc.GetSemanticModelAsync (); if (semanticModel == null) return null; var caretOffset = Editor.CaretOffset; @@ -182,6 +188,10 @@ namespace MonoDevelop.DocFood if (eventDeclaration != null) { node = eventDeclaration.Declaration.Variables.First (); } + + if (node.Span.Contains (caretOffset)) + return null; + var declaredSymbol = semanticModel.GetDeclaredSymbol (node); if (declaredSymbol != null) return declaredSymbol; |