提交 eaeb63fc 编写于 作者: P Paul Vick

Merge remote-tracking branch 'upstream/dev15.2.x' into merges/dev15.2.x-to-master-20170425-070007

...@@ -32868,7 +32868,11 @@ static void G(out object o) ...@@ -32868,7 +32868,11 @@ static void G(out object o)
o = null; o = null;
} }
}"; }";
<<<<<<< HEAD
var comp = CreateStandardCompilation(source); var comp = CreateStandardCompilation(source);
=======
var comp = CreateCompilationWithMscorlib(source);
>>>>>>> upstream/dev15.2.x
var tree = comp.SyntaxTrees.Single(); var tree = comp.SyntaxTrees.Single();
var model = comp.GetSemanticModel(tree); var model = comp.GetSemanticModel(tree);
var identifierBefore = GetReferences(tree, "G").Single(); var identifierBefore = GetReferences(tree, "G").Single();
...@@ -32882,6 +32886,7 @@ static void G(out object o) ...@@ -32882,6 +32886,7 @@ static void G(out object o)
var info = model.GetSymbolInfo(identifierAfter); var info = model.GetSymbolInfo(identifierAfter);
Assert.Equal("void C.G(out System.Object o)", info.Symbol.ToTestDisplayString()); Assert.Equal("void C.G(out System.Object o)", info.Symbol.ToTestDisplayString());
} }
<<<<<<< HEAD
[Fact] [Fact]
[WorkItem(10604, "https://github.com/dotnet/roslyn/issues/10604")] [WorkItem(10604, "https://github.com/dotnet/roslyn/issues/10604")]
...@@ -32912,6 +32917,8 @@ IEnumerable<object> M2(out int j) ...@@ -32912,6 +32917,8 @@ IEnumerable<object> M2(out int j)
Assert.Equal("System.Collections.Generic.IEnumerator<System.Object> System.Collections.Generic.IEnumerable<System.Object>.GetEnumerator()", Assert.Equal("System.Collections.Generic.IEnumerator<System.Object> System.Collections.Generic.IEnumerable<System.Object>.GetEnumerator()",
info.GetEnumeratorMethod.ToTestDisplayString()); info.GetEnumeratorMethod.ToTestDisplayString());
} }
=======
>>>>>>> upstream/dev15.2.x
} }
internal static class OutVarTestsExtensions internal static class OutVarTestsExtensions
...@@ -220,7 +220,7 @@ class D { } ...@@ -220,7 +220,7 @@ class D { }
await VerifyRootTypeNameAsync(workspace, "C"); await VerifyRootTypeNameAsync(workspace, "C");
workspace.OnDocumentClosed(document.Id); workspace.CloseDocument(document.Id);
} }
} }
...@@ -405,7 +405,7 @@ public void TestRemoveProjectWithClosedDocuments() ...@@ -405,7 +405,7 @@ public void TestRemoveProjectWithClosedDocuments()
workspace.AddTestProject(project1); workspace.AddTestProject(project1);
workspace.OnDocumentOpened(document.Id, document.GetOpenTextContainer()); workspace.OnDocumentOpened(document.Id, document.GetOpenTextContainer());
workspace.OnDocumentClosed(document.Id); workspace.CloseDocument(document.Id);
workspace.OnProjectRemoved(project1.Id); workspace.OnProjectRemoved(project1.Id);
} }
} }
...@@ -425,7 +425,7 @@ public void TestRemoveOpenedDocument() ...@@ -425,7 +425,7 @@ public void TestRemoveOpenedDocument()
Assert.Throws<ArgumentException>(() => workspace.OnDocumentRemoved(document.Id)); Assert.Throws<ArgumentException>(() => workspace.OnDocumentRemoved(document.Id));
workspace.OnDocumentClosed(document.Id); workspace.CloseDocument(document.Id);
workspace.OnProjectRemoved(project1.Id); workspace.OnProjectRemoved(project1.Id);
} }
} }
...@@ -692,7 +692,7 @@ public async Task TestOpenAndChangeDocument() ...@@ -692,7 +692,7 @@ public async Task TestOpenAndChangeDocument()
var syntaxTree = await doc.GetSyntaxTreeAsync(CancellationToken.None); var syntaxTree = await doc.GetSyntaxTreeAsync(CancellationToken.None);
Assert.True(syntaxTree.GetRoot().Width() > 0, "syntaxTree.GetRoot().Width should be > 0"); Assert.True(syntaxTree.GetRoot().Width() > 0, "syntaxTree.GetRoot().Width should be > 0");
workspace.OnDocumentClosed(document.Id); workspace.CloseDocument(document.Id);
workspace.OnProjectRemoved(project1.Id); workspace.OnProjectRemoved(project1.Id);
} }
} }
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Linq; using System.Linq;
...@@ -20,7 +21,7 @@ public class TestHostDocument ...@@ -20,7 +21,7 @@ public class TestHostDocument
{ {
private readonly ExportProvider _exportProvider; private readonly ExportProvider _exportProvider;
private HostLanguageServices _languageServiceProvider; private HostLanguageServices _languageServiceProvider;
private readonly string _initialText; private readonly Lazy<string> _initialText;
private IWpfTextView _textView; private IWpfTextView _textView;
private DocumentId _id; private DocumentId _id;
...@@ -32,7 +33,6 @@ public class TestHostDocument ...@@ -32,7 +33,6 @@ public class TestHostDocument
private readonly SourceCodeKind _sourceCodeKind; private readonly SourceCodeKind _sourceCodeKind;
private readonly string _filePath; private readonly string _filePath;
private readonly IReadOnlyList<string> _folders; private readonly IReadOnlyList<string> _folders;
private readonly TextLoader _loader;
public DocumentId Id public DocumentId Id
{ {
...@@ -82,14 +82,7 @@ public bool IsGenerated ...@@ -82,14 +82,7 @@ public bool IsGenerated
} }
} }
public TextLoader Loader public TextLoader Loader { get; }
{
get
{
return _loader;
}
}
public int? CursorPosition { get; } public int? CursorPosition { get; }
public IList<TextSpan> SelectedSpans { get; } public IList<TextSpan> SelectedSpans { get; }
public IDictionary<string, ImmutableArray<TextSpan>> AnnotatedSpans { get; } public IDictionary<string, ImmutableArray<TextSpan>> AnnotatedSpans { get; }
...@@ -118,6 +111,7 @@ public TextLoader Loader ...@@ -118,6 +111,7 @@ public TextLoader Loader
_languageServiceProvider = languageServiceProvider; _languageServiceProvider = languageServiceProvider;
this.TextBuffer = textBuffer; this.TextBuffer = textBuffer;
this.InitialTextSnapshot = textBuffer.CurrentSnapshot; this.InitialTextSnapshot = textBuffer.CurrentSnapshot;
_initialText = new Lazy<string>(() => this.InitialTextSnapshot.GetText());
_filePath = filePath; _filePath = filePath;
_folders = folders; _folders = folders;
_name = filePath; _name = filePath;
...@@ -137,7 +131,7 @@ public TextLoader Loader ...@@ -137,7 +131,7 @@ public TextLoader Loader
this.AnnotatedSpans.Add(namedSpanList); this.AnnotatedSpans.Add(namedSpanList);
} }
_loader = new TestDocumentLoader(this); Loader = new TestDocumentLoader(this);
} }
public TestHostDocument( public TestHostDocument(
...@@ -148,10 +142,10 @@ public TextLoader Loader ...@@ -148,10 +142,10 @@ public TextLoader Loader
{ {
_exportProvider = TestExportProvider.ExportProviderWithCSharpAndVisualBasic; _exportProvider = TestExportProvider.ExportProviderWithCSharpAndVisualBasic;
_id = id; _id = id;
_initialText = text; _initialText = new Lazy<string>(() => text);
_name = displayName; _name = displayName;
_sourceCodeKind = sourceCodeKind; _sourceCodeKind = sourceCodeKind;
_loader = new TestDocumentLoader(this); Loader = new TestDocumentLoader(this);
_filePath = filePath; _filePath = filePath;
_folders = folders; _folders = folders;
} }
...@@ -178,7 +172,7 @@ internal void SetProject(TestHostProject project) ...@@ -178,7 +172,7 @@ internal void SetProject(TestHostProject project)
{ {
var contentTypeService = _languageServiceProvider.GetService<IContentTypeLanguageService>(); var contentTypeService = _languageServiceProvider.GetService<IContentTypeLanguageService>();
var contentType = contentTypeService.GetDefaultContentType(); var contentType = contentTypeService.GetDefaultContentType();
this.TextBuffer = _exportProvider.GetExportedValue<ITextBufferFactoryService>().CreateTextBuffer(_initialText, contentType); this.TextBuffer = _exportProvider.GetExportedValue<ITextBufferFactoryService>().CreateTextBuffer(_initialText.Value, contentType);
this.InitialTextSnapshot = this.TextBuffer.CurrentSnapshot; this.InitialTextSnapshot = this.TextBuffer.CurrentSnapshot;
} }
} }
...@@ -194,18 +188,13 @@ internal TestDocumentLoader(TestHostDocument hostDocument) ...@@ -194,18 +188,13 @@ internal TestDocumentLoader(TestHostDocument hostDocument)
public override Task<TextAndVersion> LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken) public override Task<TextAndVersion> LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken)
{ {
return Task.FromResult(TextAndVersion.Create(_hostDocument.LoadText(cancellationToken), VersionStamp.Create(), "test")); // Create a simple SourceText so that way we're not backing "closed" files by editors to best reflect
} // what closed files look like in reality.
} var text = SourceText.From(_hostDocument.GetTextBuffer().CurrentSnapshot.GetText());
return Task.FromResult(TextAndVersion.Create(text, VersionStamp.Create(), _hostDocument.FilePath));
public IContentType ContentType
{
get
{
return this.TextBuffer.ContentType;
} }
} }
public IWpfTextView GetTextView() public IWpfTextView GetTextView()
{ {
if (_textView == null) if (_textView == null)
...@@ -234,12 +223,6 @@ public ITextBuffer GetTextBuffer() ...@@ -234,12 +223,6 @@ public ITextBuffer GetTextBuffer()
return this.TextBuffer; return this.TextBuffer;
} }
public SourceText LoadText(CancellationToken cancellationToken = default(CancellationToken))
{
var loadedBuffer = _exportProvider.GetExportedValue<ITextBufferFactoryService>().CreateTextBuffer(this.InitialTextSnapshot.GetText(), this.InitialTextSnapshot.ContentType);
return loadedBuffer.CurrentSnapshot.AsText();
}
public SourceTextContainer GetOpenTextContainer() public SourceTextContainer GetOpenTextContainer()
{ {
return this.GetTextBuffer().AsTextContainer(); return this.GetTextBuffer().AsTextContainer();
......
...@@ -211,13 +211,7 @@ public new void OnDocumentOpened(DocumentId documentId, SourceTextContainer text ...@@ -211,13 +211,7 @@ public new void OnDocumentOpened(DocumentId documentId, SourceTextContainer text
{ {
base.OnDocumentOpened(documentId, textContainer, isCurrentContext); base.OnDocumentOpened(documentId, textContainer, isCurrentContext);
} }
public void OnDocumentClosed(DocumentId documentId)
{
var testDocument = this.GetTestDocument(documentId);
this.OnDocumentClosed(documentId, testDocument.Loader);
}
public new void OnParseOptionsChanged(ProjectId projectId, ParseOptions parseOptions) public new void OnParseOptionsChanged(ProjectId projectId, ParseOptions parseOptions)
{ {
base.OnParseOptionsChanged(projectId, parseOptions); base.OnParseOptionsChanged(projectId, parseOptions);
...@@ -605,15 +599,14 @@ public TestHostDocument CreateProjectionBufferDocument(string markup, IList<Test ...@@ -605,15 +599,14 @@ public TestHostDocument CreateProjectionBufferDocument(string markup, IList<Test
public override void OpenDocument(DocumentId documentId, bool activate = true) public override void OpenDocument(DocumentId documentId, bool activate = true)
{ {
OnDocumentOpened(documentId, this.CurrentSolution.GetDocument(documentId).GetTextAsync().Result.Container); var testDocument = this.GetTestDocument(documentId);
OnDocumentOpened(documentId, testDocument.GetOpenTextContainer());
} }
public override void CloseDocument(DocumentId documentId) public override void CloseDocument(DocumentId documentId)
{ {
var currentDoc = this.CurrentSolution.GetDocument(documentId); var testDocument = this.GetTestDocument(documentId);
this.OnDocumentClosed(documentId, testDocument.Loader);
OnDocumentClosed(documentId,
TextLoader.From(TextAndVersion.Create(currentDoc.GetTextAsync().Result, currentDoc.GetTextVersionAsync().Result)));
} }
public void ChangeDocument(DocumentId documentId, SourceText text) public void ChangeDocument(DocumentId documentId, SourceText text)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities; using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
...@@ -18,22 +19,16 @@ internal partial class CSharpCodeModelService ...@@ -18,22 +19,16 @@ internal partial class CSharpCodeModelService
{ {
protected override AbstractNodeLocator CreateNodeLocator() protected override AbstractNodeLocator CreateNodeLocator()
{ {
return new NodeLocator(this); return new NodeLocator();
} }
private class NodeLocator : AbstractNodeLocator private class NodeLocator : AbstractNodeLocator
{ {
public NodeLocator(CSharpCodeModelService codeModelService) protected override string LanguageName => LanguageNames.CSharp;
: base(codeModelService)
{
}
protected override EnvDTE.vsCMPart DefaultPart protected override EnvDTE.vsCMPart DefaultPart => EnvDTE.vsCMPart.vsCMPartWholeWithAttributes;
{
get { return EnvDTE.vsCMPart.vsCMPartWholeWithAttributes; }
}
protected override VirtualTreePoint? GetStartPoint(SourceText text, SyntaxNode node, EnvDTE.vsCMPart part) protected override VirtualTreePoint? GetStartPoint(SourceText text, OptionSet options, SyntaxNode node, EnvDTE.vsCMPart part)
{ {
switch (node.Kind()) switch (node.Kind())
{ {
...@@ -53,16 +48,16 @@ protected override EnvDTE.vsCMPart DefaultPart ...@@ -53,16 +48,16 @@ protected override EnvDTE.vsCMPart DefaultPart
case SyntaxKind.DestructorDeclaration: case SyntaxKind.DestructorDeclaration:
case SyntaxKind.OperatorDeclaration: case SyntaxKind.OperatorDeclaration:
case SyntaxKind.ConversionOperatorDeclaration: case SyntaxKind.ConversionOperatorDeclaration:
return GetStartPoint(text, (BaseMethodDeclarationSyntax)node, part); return GetStartPoint(text, options, (BaseMethodDeclarationSyntax)node, part);
case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertyDeclaration:
case SyntaxKind.IndexerDeclaration: case SyntaxKind.IndexerDeclaration:
case SyntaxKind.EventDeclaration: case SyntaxKind.EventDeclaration:
return GetStartPoint(text, (BasePropertyDeclarationSyntax)node, part); return GetStartPoint(text, options, (BasePropertyDeclarationSyntax)node, part);
case SyntaxKind.GetAccessorDeclaration: case SyntaxKind.GetAccessorDeclaration:
case SyntaxKind.SetAccessorDeclaration: case SyntaxKind.SetAccessorDeclaration:
case SyntaxKind.AddAccessorDeclaration: case SyntaxKind.AddAccessorDeclaration:
case SyntaxKind.RemoveAccessorDeclaration: case SyntaxKind.RemoveAccessorDeclaration:
return GetStartPoint(text, (AccessorDeclarationSyntax)node, part); return GetStartPoint(text, options, (AccessorDeclarationSyntax)node, part);
case SyntaxKind.DelegateDeclaration: case SyntaxKind.DelegateDeclaration:
return GetStartPoint(text, (DelegateDeclarationSyntax)node, part); return GetStartPoint(text, (DelegateDeclarationSyntax)node, part);
case SyntaxKind.NamespaceDeclaration: case SyntaxKind.NamespaceDeclaration:
...@@ -81,7 +76,7 @@ protected override EnvDTE.vsCMPart DefaultPart ...@@ -81,7 +76,7 @@ protected override EnvDTE.vsCMPart DefaultPart
} }
} }
protected override VirtualTreePoint? GetEndPoint(SourceText text, SyntaxNode node, EnvDTE.vsCMPart part) protected override VirtualTreePoint? GetEndPoint(SourceText text, OptionSet options, SyntaxNode node, EnvDTE.vsCMPart part)
{ {
switch (node.Kind()) switch (node.Kind())
{ {
...@@ -141,7 +136,7 @@ private VirtualTreePoint GetBodyStartPoint(SourceText text, SyntaxToken openBrac ...@@ -141,7 +136,7 @@ private VirtualTreePoint GetBodyStartPoint(SourceText text, SyntaxToken openBrac
: new VirtualTreePoint(openBrace.SyntaxTree, text, openBrace.Span.End); : new VirtualTreePoint(openBrace.SyntaxTree, text, openBrace.Span.End);
} }
private VirtualTreePoint GetBodyStartPoint(SourceText text, SyntaxToken openBrace, SyntaxToken closeBrace, int memberStartColumn) private VirtualTreePoint GetBodyStartPoint(SourceText text, OptionSet options, SyntaxToken openBrace, SyntaxToken closeBrace, int memberStartColumn)
{ {
Debug.Assert(!openBrace.IsMissing); Debug.Assert(!openBrace.IsMissing);
Debug.Assert(!closeBrace.IsMissing); Debug.Assert(!closeBrace.IsMissing);
...@@ -181,7 +176,7 @@ private VirtualTreePoint GetBodyStartPoint(SourceText text, SyntaxToken openBrac ...@@ -181,7 +176,7 @@ private VirtualTreePoint GetBodyStartPoint(SourceText text, SyntaxToken openBrac
// If the line is all whitespace then place the caret at the first indent after the start // If the line is all whitespace then place the caret at the first indent after the start
// of the member. // of the member.
var indentSize = GetTabSize(text); var indentSize = GetTabSize(options);
var lineText = lineAfterOpenBrace.ToString(); var lineText = lineAfterOpenBrace.ToString();
var lineEndColumn = lineText.GetColumnFromLineOffset(lineText.Length, indentSize); var lineEndColumn = lineText.GetColumnFromLineOffset(lineText.Length, indentSize);
...@@ -347,7 +342,7 @@ private VirtualTreePoint GetStartPoint(SourceText text, BaseTypeDeclarationSynta ...@@ -347,7 +342,7 @@ private VirtualTreePoint GetStartPoint(SourceText text, BaseTypeDeclarationSynta
return new VirtualTreePoint(node.SyntaxTree, text, startPosition); return new VirtualTreePoint(node.SyntaxTree, text, startPosition);
} }
private VirtualTreePoint GetStartPoint(SourceText text, BaseMethodDeclarationSyntax node, EnvDTE.vsCMPart part) private VirtualTreePoint GetStartPoint(SourceText text, OptionSet options, BaseMethodDeclarationSyntax node, EnvDTE.vsCMPart part)
{ {
int startPosition; int startPosition;
...@@ -380,9 +375,9 @@ private VirtualTreePoint GetStartPoint(SourceText text, BaseMethodDeclarationSyn ...@@ -380,9 +375,9 @@ private VirtualTreePoint GetStartPoint(SourceText text, BaseMethodDeclarationSyn
if (node.Body != null && !node.Body.OpenBraceToken.IsMissing) if (node.Body != null && !node.Body.OpenBraceToken.IsMissing)
{ {
var line = text.Lines.GetLineFromPosition(node.SpanStart); var line = text.Lines.GetLineFromPosition(node.SpanStart);
var indentation = line.GetColumnOfFirstNonWhitespaceCharacterOrEndOfLine(GetTabSize(text)); var indentation = line.GetColumnOfFirstNonWhitespaceCharacterOrEndOfLine(GetTabSize(options));
return GetBodyStartPoint(text, node.Body.OpenBraceToken, node.Body.CloseBraceToken, indentation); return GetBodyStartPoint(text, options, node.Body.OpenBraceToken, node.Body.CloseBraceToken, indentation);
} }
else else
{ {
...@@ -436,7 +431,7 @@ private AccessorDeclarationSyntax FindFirstAccessorNode(BasePropertyDeclarationS ...@@ -436,7 +431,7 @@ private AccessorDeclarationSyntax FindFirstAccessorNode(BasePropertyDeclarationS
return node.AccessorList.Accessors.FirstOrDefault(); return node.AccessorList.Accessors.FirstOrDefault();
} }
private VirtualTreePoint GetStartPoint(SourceText text, BasePropertyDeclarationSyntax node, EnvDTE.vsCMPart part) private VirtualTreePoint GetStartPoint(SourceText text, OptionSet options, BasePropertyDeclarationSyntax node, EnvDTE.vsCMPart part)
{ {
int startPosition; int startPosition;
...@@ -467,17 +462,17 @@ private VirtualTreePoint GetStartPoint(SourceText text, BasePropertyDeclarationS ...@@ -467,17 +462,17 @@ private VirtualTreePoint GetStartPoint(SourceText text, BasePropertyDeclarationS
if (firstAccessorNode != null) if (firstAccessorNode != null)
{ {
var line = text.Lines.GetLineFromPosition(firstAccessorNode.SpanStart); var line = text.Lines.GetLineFromPosition(firstAccessorNode.SpanStart);
var indentation = line.GetColumnOfFirstNonWhitespaceCharacterOrEndOfLine(GetTabSize(text)); var indentation = line.GetColumnOfFirstNonWhitespaceCharacterOrEndOfLine(GetTabSize(options));
if (firstAccessorNode.Body != null) if (firstAccessorNode.Body != null)
{ {
return GetBodyStartPoint(text, firstAccessorNode.Body.OpenBraceToken, firstAccessorNode.Body.CloseBraceToken, indentation); return GetBodyStartPoint(text, options, firstAccessorNode.Body.OpenBraceToken, firstAccessorNode.Body.CloseBraceToken, indentation);
} }
else if (!firstAccessorNode.SemicolonToken.IsMissing) else if (!firstAccessorNode.SemicolonToken.IsMissing)
{ {
// This is total weirdness from the old C# code model with auto props. // This is total weirdness from the old C# code model with auto props.
// If there isn't a body, the semi-colon is used // If there isn't a body, the semi-colon is used
return GetBodyStartPoint(text, firstAccessorNode.SemicolonToken, firstAccessorNode.SemicolonToken, indentation); return GetBodyStartPoint(text, options, firstAccessorNode.SemicolonToken, firstAccessorNode.SemicolonToken, indentation);
} }
} }
...@@ -487,9 +482,9 @@ private VirtualTreePoint GetStartPoint(SourceText text, BasePropertyDeclarationS ...@@ -487,9 +482,9 @@ private VirtualTreePoint GetStartPoint(SourceText text, BasePropertyDeclarationS
if (node.AccessorList != null && !node.AccessorList.OpenBraceToken.IsMissing) if (node.AccessorList != null && !node.AccessorList.OpenBraceToken.IsMissing)
{ {
var line = text.Lines.GetLineFromPosition(node.SpanStart); var line = text.Lines.GetLineFromPosition(node.SpanStart);
var indentation = line.GetColumnOfFirstNonWhitespaceCharacterOrEndOfLine(GetTabSize(text)); var indentation = line.GetColumnOfFirstNonWhitespaceCharacterOrEndOfLine(GetTabSize(options));
return GetBodyStartPoint(text, node.AccessorList.OpenBraceToken, node.AccessorList.CloseBraceToken, indentation); return GetBodyStartPoint(text, options, node.AccessorList.OpenBraceToken, node.AccessorList.CloseBraceToken, indentation);
} }
throw Exceptions.ThrowEFail(); throw Exceptions.ThrowEFail();
...@@ -501,7 +496,7 @@ private VirtualTreePoint GetStartPoint(SourceText text, BasePropertyDeclarationS ...@@ -501,7 +496,7 @@ private VirtualTreePoint GetStartPoint(SourceText text, BasePropertyDeclarationS
return new VirtualTreePoint(node.SyntaxTree, text, startPosition); return new VirtualTreePoint(node.SyntaxTree, text, startPosition);
} }
private VirtualTreePoint GetStartPoint(SourceText text, AccessorDeclarationSyntax node, EnvDTE.vsCMPart part) private VirtualTreePoint GetStartPoint(SourceText text, OptionSet options, AccessorDeclarationSyntax node, EnvDTE.vsCMPart part)
{ {
int startPosition; int startPosition;
...@@ -526,9 +521,9 @@ private VirtualTreePoint GetStartPoint(SourceText text, AccessorDeclarationSynta ...@@ -526,9 +521,9 @@ private VirtualTreePoint GetStartPoint(SourceText text, AccessorDeclarationSynta
if (node.Body != null && !node.Body.OpenBraceToken.IsMissing) if (node.Body != null && !node.Body.OpenBraceToken.IsMissing)
{ {
var line = text.Lines.GetLineFromPosition(node.SpanStart); var line = text.Lines.GetLineFromPosition(node.SpanStart);
var indentation = line.GetColumnOfFirstNonWhitespaceCharacterOrEndOfLine(GetTabSize(text)); var indentation = line.GetColumnOfFirstNonWhitespaceCharacterOrEndOfLine(GetTabSize(options));
return GetBodyStartPoint(text, node.Body.OpenBraceToken, node.Body.CloseBraceToken, indentation); return GetBodyStartPoint(text, options, node.Body.OpenBraceToken, node.Body.CloseBraceToken, indentation);
} }
throw Exceptions.ThrowEFail(); throw Exceptions.ThrowEFail();
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Options;
namespace Microsoft.VisualStudio.LanguageServices.Implementation namespace Microsoft.VisualStudio.LanguageServices.Implementation
{ {
...@@ -11,11 +12,11 @@ internal interface ICodeModelNavigationPointService : ILanguageService ...@@ -11,11 +12,11 @@ internal interface ICodeModelNavigationPointService : ILanguageService
/// <summary> /// <summary>
/// Retrieves the start point of a given node for the specified EnvDTE.vsCMPart. /// Retrieves the start point of a given node for the specified EnvDTE.vsCMPart.
/// </summary> /// </summary>
VirtualTreePoint? GetStartPoint(SyntaxNode node, EnvDTE.vsCMPart? part = null); VirtualTreePoint? GetStartPoint(SyntaxNode node, OptionSet options, EnvDTE.vsCMPart? part = null);
/// <summary> /// <summary>
/// Retrieves the end point of a given node for the specified EnvDTE.vsCMPart. /// Retrieves the end point of a given node for the specified EnvDTE.vsCMPart.
/// </summary> /// </summary>
VirtualTreePoint? GetEndPoint(SyntaxNode node, EnvDTE.vsCMPart? part = null); VirtualTreePoint? GetEndPoint(SyntaxNode node, OptionSet options, EnvDTE.vsCMPart? part = null);
} }
} }
...@@ -61,7 +61,8 @@ public static bool TryGetBaseClassName(Document document, string className, Canc ...@@ -61,7 +61,8 @@ public static bool TryGetBaseClassName(Document document, string className, Canc
var tree = document.GetSyntaxTreeSynchronously(cancellationToken); var tree = document.GetSyntaxTreeSynchronously(cancellationToken);
var typeNode = type.DeclaringSyntaxReferences.Where(r => r.SyntaxTree == tree).Select(r => r.GetSyntax(cancellationToken)).First(); var typeNode = type.DeclaringSyntaxReferences.Where(r => r.SyntaxTree == tree).Select(r => r.GetSyntax(cancellationToken)).First();
var codeModel = document.Project.LanguageServices.GetService<ICodeModelNavigationPointService>(); var codeModel = document.Project.LanguageServices.GetService<ICodeModelNavigationPointService>();
var point = codeModel.GetStartPoint(typeNode, EnvDTE.vsCMPart.vsCMPartBody); var options = document.GetOptionsAsync(cancellationToken).WaitAndGetResult_Venus(cancellationToken);
var point = codeModel.GetStartPoint(typeNode, options, EnvDTE.vsCMPart.vsCMPartBody);
var reservedNames = semanticModel.LookupSymbols(point.Value.Position, type).Select(m => m.Name); var reservedNames = semanticModel.LookupSymbols(point.Value.Position, type).Select(m => m.Name);
return NameGenerator.EnsureUniqueness(name, reservedNames, document.Project.LanguageServices.GetService<ISyntaxFactsService>().IsCaseSensitive); return NameGenerator.EnsureUniqueness(name, reservedNames, document.Project.LanguageServices.GetService<ISyntaxFactsService>().IsCaseSensitive);
...@@ -202,7 +203,8 @@ public static string GetEventHandlerMemberId(Document document, string className ...@@ -202,7 +203,8 @@ public static string GetEventHandlerMemberId(Document document, string className
var position = type.Locations.First(loc => loc.SourceTree == targetSyntaxTree).SourceSpan.Start; var position = type.Locations.First(loc => loc.SourceTree == targetSyntaxTree).SourceSpan.Start;
var destinationType = syntaxFacts.GetContainingTypeDeclaration(targetSyntaxTree.GetRoot(cancellationToken), position); var destinationType = syntaxFacts.GetContainingTypeDeclaration(targetSyntaxTree.GetRoot(cancellationToken), position);
var insertionPoint = codeModel.GetEndPoint(destinationType, EnvDTE.vsCMPart.vsCMPartBody); var options = targetDocument.GetOptionsAsync(cancellationToken).WaitAndGetResult_Venus(cancellationToken);
var insertionPoint = codeModel.GetEndPoint(destinationType, options, EnvDTE.vsCMPart.vsCMPartBody);
if (insertionPoint == null) if (insertionPoint == null)
{ {
...@@ -261,10 +263,12 @@ public static string GetEventHandlerMemberId(Document document, string className ...@@ -261,10 +263,12 @@ public static string GetEventHandlerMemberId(Document document, string className
var memberNode = member.DeclaringSyntaxReferences.Select(r => r.GetSyntax(cancellationToken)).FirstOrDefault(); var memberNode = member.DeclaringSyntaxReferences.Select(r => r.GetSyntax(cancellationToken)).FirstOrDefault();
if (memberNode != null) if (memberNode != null)
{ {
var navigationPoint = codeModel.GetStartPoint(memberNode, EnvDTE.vsCMPart.vsCMPartNavigate); var memberNodeDocument = thisDocument.Project.Solution.GetDocument(memberNode.SyntaxTree);
var options = memberNodeDocument.GetOptionsAsync(cancellationToken).WaitAndGetResult_Venus(cancellationToken);
var navigationPoint = codeModel.GetStartPoint(memberNode, options, EnvDTE.vsCMPart.vsCMPartNavigate);
if (navigationPoint != null) if (navigationPoint != null)
{ {
targetDocument = thisDocument.Project.Solution.GetDocument(memberNode.SyntaxTree); targetDocument = memberNodeDocument;
textSpan = navigationPoint.Value.ToVsTextSpan(); textSpan = navigationPoint.Value.ToVsTextSpan();
return true; return true;
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Text;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel namespace Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel
...@@ -12,33 +14,28 @@ internal partial class AbstractCodeModelService : ICodeModelService ...@@ -12,33 +14,28 @@ internal partial class AbstractCodeModelService : ICodeModelService
protected abstract class AbstractNodeLocator protected abstract class AbstractNodeLocator
{ {
private readonly AbstractCodeModelService _codeModelService; protected abstract string LanguageName { get; }
protected AbstractNodeLocator(AbstractCodeModelService codeModelService)
{
_codeModelService = codeModelService;
}
protected abstract EnvDTE.vsCMPart DefaultPart { get; } protected abstract EnvDTE.vsCMPart DefaultPart { get; }
protected abstract VirtualTreePoint? GetStartPoint(SourceText text, SyntaxNode node, EnvDTE.vsCMPart part); protected abstract VirtualTreePoint? GetStartPoint(SourceText text, OptionSet options, SyntaxNode node, EnvDTE.vsCMPart part);
protected abstract VirtualTreePoint? GetEndPoint(SourceText text, SyntaxNode node, EnvDTE.vsCMPart part); protected abstract VirtualTreePoint? GetEndPoint(SourceText text, OptionSet options, SyntaxNode node, EnvDTE.vsCMPart part);
protected int GetTabSize(SourceText text) protected int GetTabSize(OptionSet options)
{ {
return _codeModelService.GetTabSize(text); return options.GetOption(FormattingOptions.TabSize, LanguageName);
} }
public VirtualTreePoint? GetStartPoint(SyntaxNode node, EnvDTE.vsCMPart? part) public VirtualTreePoint? GetStartPoint(SyntaxNode node, OptionSet options, EnvDTE.vsCMPart? part)
{ {
var text = node.SyntaxTree.GetText(); var text = node.SyntaxTree.GetText();
return GetStartPoint(text, node, part ?? DefaultPart); return GetStartPoint(text, options, node, part ?? DefaultPart);
} }
public VirtualTreePoint? GetEndPoint(SyntaxNode node, EnvDTE.vsCMPart? part) public VirtualTreePoint? GetEndPoint(SyntaxNode node, OptionSet options, EnvDTE.vsCMPart? part)
{ {
var text = node.SyntaxTree.GetText(); var text = node.SyntaxTree.GetText();
return GetEndPoint(text, node, part ?? DefaultPart); return GetEndPoint(text, options, node, part ?? DefaultPart);
} }
} }
} }
......
...@@ -77,23 +77,6 @@ protected string GetNewLineCharacter(SourceText text) ...@@ -77,23 +77,6 @@ protected string GetNewLineCharacter(SourceText text)
return _editorOptionsFactoryService.GetEditorOptions(text).GetNewLineCharacter(); return _editorOptionsFactoryService.GetEditorOptions(text).GetNewLineCharacter();
} }
protected int GetTabSize(SourceText text)
{
var snapshot = text.FindCorrespondingEditorTextSnapshot();
return GetTabSize(snapshot);
}
protected int GetTabSize(ITextSnapshot snapshot)
{
if (snapshot == null)
{
throw new ArgumentNullException(nameof(snapshot));
}
var textBuffer = snapshot.TextBuffer;
return _editorOptionsFactoryService.GetOptions(textBuffer).GetTabSize();
}
protected SyntaxToken GetTokenWithoutAnnotation(SyntaxToken current, Func<SyntaxToken, SyntaxToken> nextTokenGetter) protected SyntaxToken GetTokenWithoutAnnotation(SyntaxToken current, Func<SyntaxToken, SyntaxToken> nextTokenGetter)
{ {
while (current.ContainsAnnotations) while (current.ContainsAnnotations)
...@@ -552,14 +535,14 @@ public void Rename(ISymbol symbol, string newName, Solution solution) ...@@ -552,14 +535,14 @@ public void Rename(ISymbol symbol, string newName, Solution solution)
public abstract string GetExternalSymbolName(ISymbol symbol); public abstract string GetExternalSymbolName(ISymbol symbol);
public abstract string GetExternalSymbolFullName(ISymbol symbol); public abstract string GetExternalSymbolFullName(ISymbol symbol);
public VirtualTreePoint? GetStartPoint(SyntaxNode node, EnvDTE.vsCMPart? part) public VirtualTreePoint? GetStartPoint(SyntaxNode node, OptionSet options, EnvDTE.vsCMPart? part)
{ {
return _nodeLocator.GetStartPoint(node, part); return _nodeLocator.GetStartPoint(node, options, part);
} }
public VirtualTreePoint? GetEndPoint(SyntaxNode node, EnvDTE.vsCMPart? part) public VirtualTreePoint? GetEndPoint(SyntaxNode node, OptionSet options, EnvDTE.vsCMPart? part)
{ {
return _nodeLocator.GetEndPoint(node, part); return _nodeLocator.GetEndPoint(node, options, part);
} }
public abstract EnvDTE.vsCMAccess GetAccess(ISymbol symbol); public abstract EnvDTE.vsCMAccess GetAccess(ISymbol symbol);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Threading;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.VisualStudio.LanguageServices.Implementation.Interop; using Microsoft.VisualStudio.LanguageServices.Implementation.Interop;
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities; using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
...@@ -152,7 +153,8 @@ public EnvDTE.TextPoint StartPoint ...@@ -152,7 +153,8 @@ public EnvDTE.TextPoint StartPoint
{ {
get get
{ {
var point = CodeModelService.GetStartPoint(LookupNode()); var options = GetDocument().GetOptionsAsync(CancellationToken.None).WaitAndGetResult_CodeModel(CancellationToken.None);
var point = CodeModelService.GetStartPoint(LookupNode(), options);
if (point == null) if (point == null)
{ {
return null; return null;
...@@ -166,7 +168,8 @@ public EnvDTE.TextPoint EndPoint ...@@ -166,7 +168,8 @@ public EnvDTE.TextPoint EndPoint
{ {
get get
{ {
var point = CodeModelService.GetEndPoint(LookupNode()); var options = GetDocument().GetOptionsAsync(CancellationToken.None).WaitAndGetResult_CodeModel(CancellationToken.None);
var point = CodeModelService.GetEndPoint(LookupNode(), options);
if (point == null) if (point == null)
{ {
return null; return null;
...@@ -178,7 +181,8 @@ public EnvDTE.TextPoint EndPoint ...@@ -178,7 +181,8 @@ public EnvDTE.TextPoint EndPoint
public virtual EnvDTE.TextPoint GetStartPoint(EnvDTE.vsCMPart part) public virtual EnvDTE.TextPoint GetStartPoint(EnvDTE.vsCMPart part)
{ {
var point = CodeModelService.GetStartPoint(LookupNode(), part); var options = GetDocument().GetOptionsAsync(CancellationToken.None).WaitAndGetResult_CodeModel(CancellationToken.None);
var point = CodeModelService.GetStartPoint(LookupNode(), options, part);
if (point == null) if (point == null)
{ {
return null; return null;
...@@ -189,7 +193,8 @@ public virtual EnvDTE.TextPoint GetStartPoint(EnvDTE.vsCMPart part) ...@@ -189,7 +193,8 @@ public virtual EnvDTE.TextPoint GetStartPoint(EnvDTE.vsCMPart part)
public virtual EnvDTE.TextPoint GetEndPoint(EnvDTE.vsCMPart part) public virtual EnvDTE.TextPoint GetEndPoint(EnvDTE.vsCMPart part)
{ {
var point = CodeModelService.GetEndPoint(LookupNode(), part); var options = GetDocument().GetOptionsAsync(CancellationToken.None).WaitAndGetResult_CodeModel(CancellationToken.None);
var point = CodeModelService.GetEndPoint(LookupNode(), options, part);
if (point == null) if (point == null)
{ {
return null; return null;
......
...@@ -29,6 +29,14 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel ...@@ -29,6 +29,14 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel
Assert.NotNull(codeElement) Assert.NotNull(codeElement)
expected(codeElement) expected(codeElement)
' Now close the file and ensure the behavior is still the same
state.VisualStudioWorkspace.CloseDocument(state.Workspace.Documents.Single().Id)
codeElement = GetCodeElement(state)
Assert.NotNull(codeElement)
expected(codeElement)
End Using End Using
End Sub End Sub
......
...@@ -54,8 +54,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel ...@@ -54,8 +54,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel
project.LanguageServices, project.LanguageServices,
mockVisualStudioWorkspace) mockVisualStudioWorkspace)
Dim editorOptionsFactoryService = workspace.GetService(Of IEditorOptionsFactoryService)() Dim mockTextManagerAdapter = New MockTextManagerAdapter()
Dim mockTextManagerAdapter = New MockTextManagerAdapter(editorOptionsFactoryService)
For Each documentId In project.DocumentIds For Each documentId In project.DocumentIds
' Note that a parent is not specified below. In Visual Studio, this would normally be an EnvDTE.Project instance. ' Note that a parent is not specified below. In Visual Studio, this would normally be an EnvDTE.Project instance.
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. ' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Threading
Imports Microsoft.CodeAnalysis.Editor Imports Microsoft.CodeAnalysis.Editor
Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities
Imports Microsoft.CodeAnalysis.Formatting
Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel Imports Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel
Imports Microsoft.VisualStudio.Text.Editor Imports Microsoft.VisualStudio.Text.Editor
...@@ -11,16 +13,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel.Mocks ...@@ -11,16 +13,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel.Mocks
Friend NotInheritable Class MockTextManagerAdapter Friend NotInheritable Class MockTextManagerAdapter
Implements ITextManagerAdapter Implements ITextManagerAdapter
Private ReadOnly _editorOptionsFactoryService As IEditorOptionsFactoryService
Public Sub New(editorOptionsFactoryService As IEditorOptionsFactoryService)
_editorOptionsFactoryService = editorOptionsFactoryService
End Sub
Public Function CreateTextPoint(fileCodeModel As FileCodeModel, point As VirtualTreePoint) As EnvDTE.TextPoint Implements ITextManagerAdapter.CreateTextPoint Public Function CreateTextPoint(fileCodeModel As FileCodeModel, point As VirtualTreePoint) As EnvDTE.TextPoint Implements ITextManagerAdapter.CreateTextPoint
Dim textBuffer = point.Text.Container.TryGetTextBuffer() Dim options = fileCodeModel.GetDocument().GetOptionsAsync().WaitAndGetResult_CodeModel(CancellationToken.None)
Dim tabSize = _editorOptionsFactoryService.GetOptions(textBuffer).GetTabSize() Return New MockTextPoint(point, options.GetOption(FormattingOptions.TabSize))
Return New MockTextPoint(point, tabSize)
End Function End Function
End Class End Class
End Namespace End Namespace
...@@ -96,10 +96,16 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests ...@@ -96,10 +96,16 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests
Private ReadOnly _documentId As DocumentId Private ReadOnly _documentId As DocumentId
Private ReadOnly _workspace As TestWorkspace Private ReadOnly _workspace As TestWorkspace
Private ReadOnly _needsClose As Boolean = False
Public Sub New(documentId As DocumentId, workspace As TestWorkspace) Public Sub New(documentId As DocumentId, workspace As TestWorkspace)
Me._documentId = documentId Me._documentId = documentId
Me._workspace = workspace Me._workspace = workspace
If Not workspace.IsDocumentOpen(documentId) Then
_workspace.OpenDocument(documentId)
_needsClose = True
End If
End Sub End Sub
Public ReadOnly Property TextBuffer As Global.Microsoft.VisualStudio.Text.ITextBuffer Implements IInvisibleEditor.TextBuffer Public ReadOnly Property TextBuffer As Global.Microsoft.VisualStudio.Text.ITextBuffer Implements IInvisibleEditor.TextBuffer
...@@ -109,6 +115,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests ...@@ -109,6 +115,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests
End Property End Property
Public Sub Dispose() Implements IDisposable.Dispose Public Sub Dispose() Implements IDisposable.Dispose
If _needsClose Then
_workspace.CloseDocument(_documentId)
End If
End Sub End Sub
End Class End Class
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities Imports Microsoft.CodeAnalysis.Editor.Shared.Utilities
Imports Microsoft.CodeAnalysis.Editor.VisualBasic.Utilities Imports Microsoft.CodeAnalysis.Editor.VisualBasic.Utilities
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic Imports Microsoft.CodeAnalysis.VisualBasic
Imports Microsoft.CodeAnalysis.VisualBasic.Extensions Imports Microsoft.CodeAnalysis.VisualBasic.Extensions
...@@ -13,15 +14,17 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -13,15 +14,17 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
Partial Friend Class VisualBasicCodeModelService Partial Friend Class VisualBasicCodeModelService
Protected Overrides Function CreateNodeLocator() As AbstractNodeLocator Protected Overrides Function CreateNodeLocator() As AbstractNodeLocator
Return New NodeLocator(Me) Return New NodeLocator()
End Function End Function
Private Class NodeLocator Private Class NodeLocator
Inherits AbstractNodeLocator Inherits AbstractNodeLocator
Public Sub New(codeModelService As VisualBasicCodeModelService) Protected Overrides ReadOnly Property LanguageName As String
MyBase.New(codeModelService) Get
End Sub Return LanguageNames.VisualBasic
End Get
End Property
Protected Overrides ReadOnly Property DefaultPart As EnvDTE.vsCMPart Protected Overrides ReadOnly Property DefaultPart As EnvDTE.vsCMPart
Get Get
...@@ -29,22 +32,22 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -29,22 +32,22 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
End Get End Get
End Property End Property
Protected Overrides Function GetStartPoint(text As SourceText, node As SyntaxNode, part As EnvDTE.vsCMPart) As VirtualTreePoint? Protected Overrides Function GetStartPoint(text As SourceText, options As OptionSet, node As SyntaxNode, part As EnvDTE.vsCMPart) As VirtualTreePoint?
Select Case node.Kind Select Case node.Kind
Case SyntaxKind.ClassBlock, Case SyntaxKind.ClassBlock,
SyntaxKind.InterfaceBlock, SyntaxKind.InterfaceBlock,
SyntaxKind.ModuleBlock, SyntaxKind.ModuleBlock,
SyntaxKind.StructureBlock SyntaxKind.StructureBlock
Return GetTypeBlockStartPoint(text, DirectCast(node, TypeBlockSyntax), part) Return GetTypeBlockStartPoint(text, options, DirectCast(node, TypeBlockSyntax), part)
Case SyntaxKind.EnumBlock Case SyntaxKind.EnumBlock
Return GetEnumBlockStartPoint(text, DirectCast(node, EnumBlockSyntax), part) Return GetEnumBlockStartPoint(text, options, DirectCast(node, EnumBlockSyntax), part)
Case SyntaxKind.ClassStatement, Case SyntaxKind.ClassStatement,
SyntaxKind.InterfaceStatement, SyntaxKind.InterfaceStatement,
SyntaxKind.ModuleStatement, SyntaxKind.ModuleStatement,
SyntaxKind.StructureStatement SyntaxKind.StructureStatement
Return GetTypeBlockStartPoint(text, DirectCast(node.Parent, TypeBlockSyntax), part) Return GetTypeBlockStartPoint(text, options, DirectCast(node.Parent, TypeBlockSyntax), part)
Case SyntaxKind.EnumStatement Case SyntaxKind.EnumStatement
Return GetEnumBlockStartPoint(text, DirectCast(node.Parent, EnumBlockSyntax), part) Return GetEnumBlockStartPoint(text, options, DirectCast(node.Parent, EnumBlockSyntax), part)
Case SyntaxKind.ConstructorBlock, Case SyntaxKind.ConstructorBlock,
SyntaxKind.FunctionBlock, SyntaxKind.FunctionBlock,
SyntaxKind.OperatorBlock, SyntaxKind.OperatorBlock,
...@@ -54,7 +57,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -54,7 +57,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
SyntaxKind.AddHandlerAccessorBlock, SyntaxKind.AddHandlerAccessorBlock,
SyntaxKind.RemoveHandlerAccessorBlock, SyntaxKind.RemoveHandlerAccessorBlock,
SyntaxKind.RaiseEventAccessorBlock SyntaxKind.RaiseEventAccessorBlock
Return GetMethodBlockStartPoint(text, DirectCast(node, MethodBlockBaseSyntax), part) Return GetMethodBlockStartPoint(text, options, DirectCast(node, MethodBlockBaseSyntax), part)
Case SyntaxKind.SubNewStatement, Case SyntaxKind.SubNewStatement,
SyntaxKind.OperatorStatement, SyntaxKind.OperatorStatement,
SyntaxKind.GetAccessorStatement, SyntaxKind.GetAccessorStatement,
...@@ -62,11 +65,11 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -62,11 +65,11 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
SyntaxKind.AddHandlerStatement, SyntaxKind.AddHandlerStatement,
SyntaxKind.RemoveHandlerStatement, SyntaxKind.RemoveHandlerStatement,
SyntaxKind.RaiseEventStatement SyntaxKind.RaiseEventStatement
Return GetMethodBlockStartPoint(text, DirectCast(node.Parent, MethodBlockBaseSyntax), part) Return GetMethodBlockStartPoint(text, options, DirectCast(node.Parent, MethodBlockBaseSyntax), part)
Case SyntaxKind.FunctionStatement, Case SyntaxKind.FunctionStatement,
SyntaxKind.SubStatement SyntaxKind.SubStatement
If TypeOf node.Parent Is MethodBlockBaseSyntax Then If TypeOf node.Parent Is MethodBlockBaseSyntax Then
Return GetMethodBlockStartPoint(text, DirectCast(node.Parent, MethodBlockBaseSyntax), part) Return GetMethodBlockStartPoint(text, options, DirectCast(node.Parent, MethodBlockBaseSyntax), part)
Else Else
Return GetMethodStatementStartPoint(text, DirectCast(node, MethodStatementSyntax), part) Return GetMethodStatementStartPoint(text, DirectCast(node, MethodStatementSyntax), part)
End If End If
...@@ -80,7 +83,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -80,7 +83,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
Return GetPropertyStatementStartPoint(text, DirectCast(node, PropertyStatementSyntax), part) Return GetPropertyStatementStartPoint(text, DirectCast(node, PropertyStatementSyntax), part)
Case SyntaxKind.EventBlock Case SyntaxKind.EventBlock
Return GetEventBlockStartPoint(text, DirectCast(node, EventBlockSyntax), part) Return GetEventBlockStartPoint(text, options, DirectCast(node, EventBlockSyntax), part)
Case SyntaxKind.EventStatement Case SyntaxKind.EventStatement
Return GetEventStatementStartPoint(text, DirectCast(node, EventStatementSyntax), part) Return GetEventStatementStartPoint(text, DirectCast(node, EventStatementSyntax), part)
...@@ -89,9 +92,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -89,9 +92,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
Return GetDelegateStatementStartPoint(text, DirectCast(node, DelegateStatementSyntax), part) Return GetDelegateStatementStartPoint(text, DirectCast(node, DelegateStatementSyntax), part)
Case SyntaxKind.NamespaceBlock Case SyntaxKind.NamespaceBlock
Return GetNamespaceBlockStartPoint(text, DirectCast(node, NamespaceBlockSyntax), part) Return GetNamespaceBlockStartPoint(text, options, DirectCast(node, NamespaceBlockSyntax), part)
Case SyntaxKind.NamespaceStatement Case SyntaxKind.NamespaceStatement
Return GetNamespaceBlockStartPoint(text, DirectCast(node.Parent, NamespaceBlockSyntax), part) Return GetNamespaceBlockStartPoint(text, options, DirectCast(node.Parent, NamespaceBlockSyntax), part)
Case SyntaxKind.ModifiedIdentifier Case SyntaxKind.ModifiedIdentifier
Return GetVariableStartPoint(text, DirectCast(node, ModifiedIdentifierSyntax), part) Return GetVariableStartPoint(text, DirectCast(node, ModifiedIdentifierSyntax), part)
Case SyntaxKind.EnumMemberDeclaration Case SyntaxKind.EnumMemberDeclaration
...@@ -119,7 +122,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -119,7 +122,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
End Select End Select
End Function End Function
Protected Overrides Function GetEndPoint(text As SourceText, node As SyntaxNode, part As EnvDTE.vsCMPart) As VirtualTreePoint? Protected Overrides Function GetEndPoint(text As SourceText, options As OptionSet, node As SyntaxNode, part As EnvDTE.vsCMPart) As VirtualTreePoint?
Select Case node.Kind Select Case node.Kind
Case SyntaxKind.ClassBlock, Case SyntaxKind.ClassBlock,
SyntaxKind.InterfaceBlock, SyntaxKind.InterfaceBlock,
...@@ -291,7 +294,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -291,7 +294,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
End If End If
End Function End Function
Private Function GetTypeBlockStartPoint(text As SourceText, typeBlock As TypeBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint? Private Function GetTypeBlockStartPoint(text As SourceText, options As OptionSet, typeBlock As TypeBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
Dim startPosition As Integer Dim startPosition As Integer
Select Case part Select Case part
...@@ -341,7 +344,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -341,7 +344,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
End If End If
If part = EnvDTE.vsCMPart.vsCMPartNavigate Then If part = EnvDTE.vsCMPart.vsCMPartNavigate Then
Return NavigationPointHelpers.GetNavigationPoint(text, GetTabSize(text), typeBlock.BlockStatement, typeBlock.EndBlockStatement, statementLine.LineNumber + 1) Return NavigationPointHelpers.GetNavigationPoint(text, GetTabSize(options), typeBlock.BlockStatement, typeBlock.EndBlockStatement, statementLine.LineNumber + 1)
End If End If
Case Else Case Else
...@@ -377,7 +380,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -377,7 +380,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
Return New VirtualTreePoint(typeBlock.SyntaxTree, text, startPosition) Return New VirtualTreePoint(typeBlock.SyntaxTree, text, startPosition)
End Function End Function
Private Function GetEnumBlockStartPoint(text As SourceText, enumBlock As EnumBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint? Private Function GetEnumBlockStartPoint(text As SourceText, options As OptionSet, enumBlock As EnumBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
Dim startPosition As Integer Dim startPosition As Integer
Select Case part Select Case part
...@@ -412,7 +415,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -412,7 +415,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
End If End If
If part = EnvDTE.vsCMPart.vsCMPartNavigate Then If part = EnvDTE.vsCMPart.vsCMPartNavigate Then
Return NavigationPointHelpers.GetNavigationPoint(text, GetTabSize(text), enumBlock.EnumStatement, enumBlock.EndEnumStatement, statementLine.LineNumber + 1) Return NavigationPointHelpers.GetNavigationPoint(text, GetTabSize(options), enumBlock.EnumStatement, enumBlock.EndEnumStatement, statementLine.LineNumber + 1)
End If End If
Case Else Case Else
...@@ -448,7 +451,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -448,7 +451,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
Return New VirtualTreePoint(enumBlock.SyntaxTree, text, startPosition) Return New VirtualTreePoint(enumBlock.SyntaxTree, text, startPosition)
End Function End Function
Private Function GetMethodBlockStartPoint(text As SourceText, methodBlock As MethodBlockBaseSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint? Private Function GetMethodBlockStartPoint(text As SourceText, options As OptionSet, methodBlock As MethodBlockBaseSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
Dim startPosition As Integer Dim startPosition As Integer
Select Case part Select Case part
...@@ -479,7 +482,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -479,7 +482,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
Throw Exceptions.ThrowEFail() Throw Exceptions.ThrowEFail()
End If End If
Return GetEventBlockStartPoint(text, eventBlock, part) Return GetEventBlockStartPoint(text, options, eventBlock, part)
Case Else Case Else
Throw Exceptions.ThrowEFail() Throw Exceptions.ThrowEFail()
End Select End Select
...@@ -493,7 +496,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -493,7 +496,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
EnvDTE.vsCMPart.vsCMPartWhole EnvDTE.vsCMPart.vsCMPartWhole
startPosition = NavigationPointHelpers.GetHeaderStartPosition(methodBlock) startPosition = NavigationPointHelpers.GetHeaderStartPosition(methodBlock)
Case EnvDTE.vsCMPart.vsCMPartNavigate Case EnvDTE.vsCMPart.vsCMPartNavigate
Return NavigationPointHelpers.GetNavigationPoint(text, GetTabSize(text), methodBlock) Return NavigationPointHelpers.GetNavigationPoint(text, GetTabSize(options), methodBlock)
Case EnvDTE.vsCMPart.vsCMPartBody, Case EnvDTE.vsCMPart.vsCMPartBody,
EnvDTE.vsCMPart.vsCMPartBodyWithDelimiter EnvDTE.vsCMPart.vsCMPartBodyWithDelimiter
...@@ -777,7 +780,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -777,7 +780,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
Return New VirtualTreePoint(propertyStatement.SyntaxTree, text, startPosition) Return New VirtualTreePoint(propertyStatement.SyntaxTree, text, startPosition)
End Function End Function
Private Function GetEventBlockStartPoint(text As SourceText, eventBlock As EventBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint? Private Function GetEventBlockStartPoint(text As SourceText, options As OptionSet, eventBlock As EventBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
Dim startPosition As Integer Dim startPosition As Integer
Select Case part Select Case part
...@@ -802,7 +805,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -802,7 +805,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
Case EnvDTE.vsCMPart.vsCMPartNavigate Case EnvDTE.vsCMPart.vsCMPartNavigate
Return NavigationPointHelpers.GetNavigationPoint(text, GetTabSize(text), eventBlock) Return NavigationPointHelpers.GetNavigationPoint(text, GetTabSize(options), eventBlock)
Case EnvDTE.vsCMPart.vsCMPartBody, Case EnvDTE.vsCMPart.vsCMPartBody,
EnvDTE.vsCMPart.vsCMPartBodyWithDelimiter EnvDTE.vsCMPart.vsCMPartBodyWithDelimiter
...@@ -974,7 +977,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -974,7 +977,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
.FirstOrNullable(Function(t) t.Kind = SyntaxKind.ColonTrivia) .FirstOrNullable(Function(t) t.Kind = SyntaxKind.ColonTrivia)
End Function End Function
Private Function GetNamespaceBlockStartPoint(text As SourceText, namespaceBlock As NamespaceBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint? Private Function GetNamespaceBlockStartPoint(text As SourceText, options As OptionSet, namespaceBlock As NamespaceBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
Dim startPosition As Integer Dim startPosition As Integer
Select Case part Select Case part
...@@ -1003,7 +1006,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel ...@@ -1003,7 +1006,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel
lineNumber = text.Lines.IndexOf(colonTrivia.Value.SpanStart) lineNumber = text.Lines.IndexOf(colonTrivia.Value.SpanStart)
End If End If
Return NavigationPointHelpers.GetNavigationPoint(text, GetTabSize(text), namespaceBlock.NamespaceStatement, namespaceBlock.EndNamespaceStatement, lineNumber) Return NavigationPointHelpers.GetNavigationPoint(text, GetTabSize(options), namespaceBlock.NamespaceStatement, namespaceBlock.EndNamespaceStatement, lineNumber)
Case EnvDTE.vsCMPart.vsCMPartBody, Case EnvDTE.vsCMPart.vsCMPartBody,
EnvDTE.vsCMPart.vsCMPartBodyWithDelimiter EnvDTE.vsCMPart.vsCMPartBodyWithDelimiter
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册