diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs index 736145c27d..6edbcb7482 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs @@ -104,9 +104,12 @@ namespace CSharpBinding searchScope, parseInfo.UnresolvedFile, parseInfo.SyntaxTree, compilation, delegate (AstNode node, ResolveResult result) { if (document == null) { - document = new ReadOnlyDocument(textSource); + document = new ReadOnlyDocument(textSource, fileName); highlighter = SD.EditorControlService.CreateHighlighter(document); } + Identifier identifier = node.GetChildByRole(Roles.Identifier); + if (identifier != null) + node = identifier; var region = new DomRegion(fileName, node.StartLocation, node.EndLocation); int offset = document.GetOffset(node.StartLocation); int length = document.GetOffset(node.EndLocation) - offset; diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs index 62401d8f67..214e7d5e9f 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs @@ -87,12 +87,12 @@ namespace CSharpBinding.Parser else parseInfo = new ParseInformation(file, fullParseInformationRequested); - AddCommentTags(cu, parseInfo.TagComments, fileContent); + AddCommentTags(cu, parseInfo.TagComments, fileContent, parseInfo.FileName); return parseInfo; } - void AddCommentTags(SyntaxTree cu, IList tagComments, ITextSource fileContent) + void AddCommentTags(SyntaxTree cu, IList tagComments, ITextSource fileContent, FileName fileName) { ReadOnlyDocument document = null; foreach (var comment in cu.Descendants.OfType().Where(c => c.CommentType != CommentType.InactiveCode)) { @@ -100,7 +100,7 @@ namespace CSharpBinding.Parser int index = comment.Content.IndexOfAny(TaskListTokens, 0, out matchLength); if (index > -1) { if (document == null) - document = new ReadOnlyDocument(fileContent); + document = new ReadOnlyDocument(fileContent, fileName); int commentSignLength = comment.CommentType == CommentType.Documentation || comment.CommentType == CommentType.MultiLineDocumentation ? 3 : 2; int commentEndSignLength = comment.CommentType == CommentType.MultiLine || comment.CommentType == CommentType.MultiLineDocumentation ? 2 : 0; int commentStartOffset = document.GetOffset(comment.StartLocation) + commentSignLength; @@ -143,7 +143,7 @@ namespace CSharpBinding.Parser variable, csParseInfo.UnresolvedFile, csParseInfo.SyntaxTree, compilation, delegate (AstNode node, ResolveResult result) { if (document == null) { - document = new ReadOnlyDocument(fileContent); + document = new ReadOnlyDocument(fileContent, parseInfo.FileName); highlighter = SD.EditorControlService.CreateHighlighter(document); } var region = new DomRegion(parseInfo.FileName, node.StartLocation, node.EndLocation); diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SDRefactoringContext.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SDRefactoringContext.cs index ceeb017dc9..4c72eb693d 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SDRefactoringContext.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SDRefactoringContext.cs @@ -108,21 +108,21 @@ namespace CSharpBinding.Refactoring public override IDocumentLine GetLineByOffset(int offset) { if (document == null) - document = new ReadOnlyDocument(textSource); + document = new ReadOnlyDocument(textSource, resolver.UnresolvedFile.FileName); return document.GetLineByOffset(offset); } public override int GetOffset(TextLocation location) { if (document == null) - document = new ReadOnlyDocument(textSource); + document = new ReadOnlyDocument(textSource, resolver.UnresolvedFile.FileName); return document.GetOffset(location); } public override TextLocation GetLocation(int offset) { if (document == null) - document = new ReadOnlyDocument(textSource); + document = new ReadOnlyDocument(textSource, resolver.UnresolvedFile.FileName); return document.GetLocation(offset); } diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParsedFile.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParsedFile.cs index 8918e96467..8046270fe3 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParsedFile.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParsedFile.cs @@ -121,7 +121,7 @@ namespace ICSharpCode.XamlBinding public XamlDocumentVisitor(IUnresolvedFile file, ITextSource fileContent) { this.file = file; - textDocument = new ReadOnlyDocument(fileContent); + textDocument = new ReadOnlyDocument(fileContent, file.FileName); } public override void VisitDocument(AXmlDocument document) diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs index 5457f04645..13f8e538f9 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs @@ -82,7 +82,7 @@ namespace ICSharpCode.XamlBinding int index = comment.Value.IndexOfAny(TaskListTokens, 0, out matchLength); if (index > -1) { if (document == null) - document = fileContent as IDocument ?? new ReadOnlyDocument(fileContent); + document = fileContent as IDocument ?? new ReadOnlyDocument(fileContent, parseInfo.FileName); do { TextLocation startLocation = document.GetLocation(comment.StartOffset + index); int startOffset = index + comment.StartOffset; diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs index b12cfd287d..6953832c73 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs @@ -38,7 +38,7 @@ namespace ICSharpCode.XamlBinding this.parseInfo = parseInfo; this.location = location; this.compilation = compilation; - textDocument = new ReadOnlyDocument(parseInfo.Text); + textDocument = new ReadOnlyDocument(parseInfo.Text, parseInfo.FileName); offset = textDocument.GetOffset(location); AXmlObject innermost = parseInfo.Document.GetChildAtOffset(offset); diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlSymbolSearch.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlSymbolSearch.cs index 13eac29c12..7779f3f8de 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlSymbolSearch.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlSymbolSearch.cs @@ -92,7 +92,7 @@ namespace ICSharpCode.XamlBinding XamlResolver resolver = new XamlResolver(); do { if (document == null) { - document = new ReadOnlyDocument(textSource); + document = new ReadOnlyDocument(textSource, fileName); highlighter = SD.EditorControlService.CreateHighlighter(document); } var result = resolver.Resolve(parseInfo, document.GetLocation(offset + entity.Name.Length / 2 + 1), compilation, cancellationToken); diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs index 363b1f9c45..a99c278e26 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs @@ -2,6 +2,7 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; +using System.Diagnostics; using System.IO; using System.Linq; using ICSharpCode.AvalonEdit.AddIn.Options; @@ -33,6 +34,7 @@ namespace ICSharpCode.AvalonEdit.AddIn public IHighlighter CreateHighlighter(IDocument document) { + Debug.Assert(document.FileName != null, "FileName not set in " + document.GetType().FullName); var def = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(document.FileName)); var doc = document as TextDocument; if (def == null || doc == null) diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs index dc936d32cf..d021f6242d 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs @@ -230,7 +230,7 @@ namespace ICSharpCode.AvalonEdit.AddIn differ.editor.Visibility = Visibility.Collapsed; differ.copyButton.Visibility = Visibility.Collapsed; } else { - var baseDocument = new ReadOnlyDocument(changeWatcher.BaseDocument); + var baseDocument = new ReadOnlyDocument(changeWatcher.BaseDocument, TextView.Document.FileName); if (differ.editor.SyntaxHighlighting != null) { var mainHighlighter = new DocumentHighlighter(baseDocument, differ.editor.SyntaxHighlighting); var popupHighlighter = differ.editor.TextArea.GetService(typeof(IHighlighter)) as DocumentHighlighter; diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs index f760c4e48d..d1d002f08b 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs @@ -75,7 +75,7 @@ namespace ICSharpCode.AvalonEdit.AddIn Stream baseFileStream = GetBaseVersion(fileName); if (baseFileStream != null) { // ReadAll() is taking care of closing the stream - baseDocument = new ReadOnlyDocument(ReadAll(baseFileStream)); + baseDocument = new ReadOnlyDocument(ReadAll(baseFileStream), fileName); } else { // if the file is not under subversion, the document is the opened document if (baseDocument == null) { diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/XmlDoc/DocumentationUIBuilder.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/XmlDoc/DocumentationUIBuilder.cs index 7d0d27f594..54533dfbfa 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/XmlDoc/DocumentationUIBuilder.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/XmlDoc/DocumentationUIBuilder.cs @@ -200,7 +200,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.XmlDoc public void AddCodeBlock(string textContent, bool keepLargeMargin = false) { - var document = new ReadOnlyDocument(textContent); + var document = new ReadOnlyDocument(textContent, ""); var highlightingDefinition = HighlightingManager.Instance.GetDefinition("C#"); var block = DocumentPrinter.ConvertTextDocumentToBlock(document, highlightingDefinition); diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs b/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs index 919c023680..07d0b934a9 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs @@ -300,7 +300,7 @@ namespace SearchAndReplace } // try to find a result - result = Find(file, new ReadOnlyDocument(buffer), searchOffset, length); + result = Find(file, new ReadOnlyDocument(buffer, file), searchOffset, length); i++; } diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs index e4cd493425..2dbfbfabfa 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs @@ -81,17 +81,19 @@ namespace ICSharpCode.AvalonEdit.Document /// Create an empty text document. /// public TextDocument() - : this(string.Empty) + : this("", "") { } /// /// Create a new text document with the specified initial text. /// - public TextDocument(IEnumerable initialText, string fileName = null) + public TextDocument(IEnumerable initialText, string fileName) { if (initialText == null) throw new ArgumentNullException("initialText"); + if (fileName == null) + throw new ArgumentNullException("fileName"); rope = new Rope(initialText); lineTree = new DocumentLineTree(this); lineManager = new LineManager(lineTree, this); @@ -108,7 +110,7 @@ namespace ICSharpCode.AvalonEdit.Document /// /// Create a new text document with the specified initial text. /// - public TextDocument(ITextSource initialText, string fileName = null) + public TextDocument(ITextSource initialText, string fileName) : this(GetTextFromTextSource(initialText), fileName) { } @@ -351,7 +353,7 @@ namespace ICSharpCode.AvalonEdit.Document /// public IDocument CreateDocumentSnapshot() { - return new ReadOnlyDocument(this); + return new ReadOnlyDocument(this, fileName); } /// diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/ReadOnlyDocument.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/ReadOnlyDocument.cs index 7e0e9ac188..919a8ac47e 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/ReadOnlyDocument.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/ReadOnlyDocument.cs @@ -36,10 +36,12 @@ namespace ICSharpCode.NRefactory.Editor /// /// Creates a new ReadOnlyDocument from the given text source. /// - public ReadOnlyDocument(ITextSource textSource, string fileName = null) + public ReadOnlyDocument(ITextSource textSource, string fileName) { if (textSource == null) throw new ArgumentNullException("textSource"); + if (fileName == null) + throw new ArgumentNullException("fileName"); // ensure that underlying buffer is immutable this.textSource = textSource.CreateSnapshot(); this.fileName = fileName; @@ -60,7 +62,7 @@ namespace ICSharpCode.NRefactory.Editor /// /// Creates a new ReadOnlyDocument from the given string. /// - public ReadOnlyDocument(string text, string fileName = null) + public ReadOnlyDocument(string text, string fileName) : this(new StringTextSource(text), fileName) { } diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/StringBuilderDocument.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/StringBuilderDocument.cs index bcd14a939a..ad6f5ca719 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/StringBuilderDocument.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/StringBuilderDocument.cs @@ -262,7 +262,7 @@ namespace ICSharpCode.NRefactory.Editor public IDocument CreateDocumentSnapshot() { if (documentSnapshot == null) - documentSnapshot = new ReadOnlyDocument(this); + documentSnapshot = new ReadOnlyDocument(this, string.Empty); return documentSnapshot; } diff --git a/src/Main/Base/Project/Src/Editor/DocumentUtilitites.cs b/src/Main/Base/Project/Src/Editor/DocumentUtilitites.cs index 6f8783ad5e..cbfab0e2e5 100644 --- a/src/Main/Base/Project/Src/Editor/DocumentUtilitites.cs +++ b/src/Main/Base/Project/Src/Editor/DocumentUtilitites.cs @@ -26,7 +26,7 @@ namespace ICSharpCode.SharpDevelop.Editor [Obsolete("Use the TextDocument constructor instead")] public static IDocument LoadDocumentFromBuffer(ITextSource buffer) { - return new TextDocument(buffer); + return new TextDocument(buffer, null); } /// @@ -35,7 +35,7 @@ namespace ICSharpCode.SharpDevelop.Editor [Obsolete("Use the ReadOnlyDocument constructor instead")] public static IDocument LoadReadOnlyDocumentFromBuffer(ITextSource buffer) { - return new ReadOnlyDocument(buffer); + return new ReadOnlyDocument(buffer, null); } /// diff --git a/src/Main/Base/Project/Src/Gui/Pads/DefinitionViewPad.cs b/src/Main/Base/Project/Src/Gui/Pads/DefinitionViewPad.cs index 60629a3145..c714b826c7 100755 --- a/src/Main/Base/Project/Src/Gui/Pads/DefinitionViewPad.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/DefinitionViewPad.cs @@ -127,7 +127,7 @@ namespace ICSharpCode.SharpDevelop.Gui void LoadFile(string fileName) { // Load the text into the definition view's text editor. - ctl.Document = new TextDocument(SD.FileService.GetFileContent(fileName)); + ctl.Document = new TextDocument(SD.FileService.GetFileContent(fileName), fileName); currentFileName = fileName; ctl.SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName)); } diff --git a/src/Main/SharpDevelop/Workbench/WorkbenchStartup.cs b/src/Main/SharpDevelop/Workbench/WorkbenchStartup.cs index aa4a350062..ba9c8bc6c5 100644 --- a/src/Main/SharpDevelop/Workbench/WorkbenchStartup.cs +++ b/src/Main/SharpDevelop/Workbench/WorkbenchStartup.cs @@ -142,7 +142,7 @@ class Test { void Main(string[] b) { SomeMethod(b[0 + 1]); } -}"), "test.cs"); +}", "test.cs"), "test.cs"); // warm up the type system var unresolvedFile = cu.ToTypeSystem(); var pc = new ICSharpCode.NRefactory.CSharp.CSharpProjectContent().AddOrUpdateFiles(unresolvedFile);