Browse Source

make fileName in IDocument mandatory to avoid crashes

newNRvisualizers
Siegfried Pammer 13 years ago
parent
commit
ef7f6bae62
  1. 5
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs
  2. 8
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs
  3. 6
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SDRefactoringContext.cs
  4. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParsedFile.cs
  5. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs
  6. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs
  7. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlSymbolSearch.cs
  8. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditorControlService.cs
  9. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs
  10. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs
  11. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/XmlDoc/DocumentationUIBuilder.cs
  12. 2
      src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs
  13. 10
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs
  14. 6
      src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/ReadOnlyDocument.cs
  15. 2
      src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/StringBuilderDocument.cs
  16. 4
      src/Main/Base/Project/Src/Editor/DocumentUtilitites.cs
  17. 2
      src/Main/Base/Project/Src/Gui/Pads/DefinitionViewPad.cs
  18. 2
      src/Main/SharpDevelop/Workbench/WorkbenchStartup.cs

5
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/CSharpSymbolSearch.cs

@ -104,9 +104,12 @@ namespace CSharpBinding
searchScope, parseInfo.UnresolvedFile, parseInfo.SyntaxTree, compilation, searchScope, parseInfo.UnresolvedFile, parseInfo.SyntaxTree, compilation,
delegate (AstNode node, ResolveResult result) { delegate (AstNode node, ResolveResult result) {
if (document == null) { if (document == null) {
document = new ReadOnlyDocument(textSource); document = new ReadOnlyDocument(textSource, fileName);
highlighter = SD.EditorControlService.CreateHighlighter(document); 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); var region = new DomRegion(fileName, node.StartLocation, node.EndLocation);
int offset = document.GetOffset(node.StartLocation); int offset = document.GetOffset(node.StartLocation);
int length = document.GetOffset(node.EndLocation) - offset; int length = document.GetOffset(node.EndLocation) - offset;

8
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs

@ -87,12 +87,12 @@ namespace CSharpBinding.Parser
else else
parseInfo = new ParseInformation(file, fullParseInformationRequested); parseInfo = new ParseInformation(file, fullParseInformationRequested);
AddCommentTags(cu, parseInfo.TagComments, fileContent); AddCommentTags(cu, parseInfo.TagComments, fileContent, parseInfo.FileName);
return parseInfo; return parseInfo;
} }
void AddCommentTags(SyntaxTree cu, IList<TagComment> tagComments, ITextSource fileContent) void AddCommentTags(SyntaxTree cu, IList<TagComment> tagComments, ITextSource fileContent, FileName fileName)
{ {
ReadOnlyDocument document = null; ReadOnlyDocument document = null;
foreach (var comment in cu.Descendants.OfType<Comment>().Where(c => c.CommentType != CommentType.InactiveCode)) { foreach (var comment in cu.Descendants.OfType<Comment>().Where(c => c.CommentType != CommentType.InactiveCode)) {
@ -100,7 +100,7 @@ namespace CSharpBinding.Parser
int index = comment.Content.IndexOfAny(TaskListTokens, 0, out matchLength); int index = comment.Content.IndexOfAny(TaskListTokens, 0, out matchLength);
if (index > -1) { if (index > -1) {
if (document == null) 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 commentSignLength = comment.CommentType == CommentType.Documentation || comment.CommentType == CommentType.MultiLineDocumentation ? 3 : 2;
int commentEndSignLength = comment.CommentType == CommentType.MultiLine || comment.CommentType == CommentType.MultiLineDocumentation ? 2 : 0; int commentEndSignLength = comment.CommentType == CommentType.MultiLine || comment.CommentType == CommentType.MultiLineDocumentation ? 2 : 0;
int commentStartOffset = document.GetOffset(comment.StartLocation) + commentSignLength; int commentStartOffset = document.GetOffset(comment.StartLocation) + commentSignLength;
@ -143,7 +143,7 @@ namespace CSharpBinding.Parser
variable, csParseInfo.UnresolvedFile, csParseInfo.SyntaxTree, compilation, variable, csParseInfo.UnresolvedFile, csParseInfo.SyntaxTree, compilation,
delegate (AstNode node, ResolveResult result) { delegate (AstNode node, ResolveResult result) {
if (document == null) { if (document == null) {
document = new ReadOnlyDocument(fileContent); document = new ReadOnlyDocument(fileContent, parseInfo.FileName);
highlighter = SD.EditorControlService.CreateHighlighter(document); highlighter = SD.EditorControlService.CreateHighlighter(document);
} }
var region = new DomRegion(parseInfo.FileName, node.StartLocation, node.EndLocation); var region = new DomRegion(parseInfo.FileName, node.StartLocation, node.EndLocation);

6
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SDRefactoringContext.cs

@ -108,21 +108,21 @@ namespace CSharpBinding.Refactoring
public override IDocumentLine GetLineByOffset(int offset) public override IDocumentLine GetLineByOffset(int offset)
{ {
if (document == null) if (document == null)
document = new ReadOnlyDocument(textSource); document = new ReadOnlyDocument(textSource, resolver.UnresolvedFile.FileName);
return document.GetLineByOffset(offset); return document.GetLineByOffset(offset);
} }
public override int GetOffset(TextLocation location) public override int GetOffset(TextLocation location)
{ {
if (document == null) if (document == null)
document = new ReadOnlyDocument(textSource); document = new ReadOnlyDocument(textSource, resolver.UnresolvedFile.FileName);
return document.GetOffset(location); return document.GetOffset(location);
} }
public override TextLocation GetLocation(int offset) public override TextLocation GetLocation(int offset)
{ {
if (document == null) if (document == null)
document = new ReadOnlyDocument(textSource); document = new ReadOnlyDocument(textSource, resolver.UnresolvedFile.FileName);
return document.GetLocation(offset); return document.GetLocation(offset);
} }

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParsedFile.cs

@ -121,7 +121,7 @@ namespace ICSharpCode.XamlBinding
public XamlDocumentVisitor(IUnresolvedFile file, ITextSource fileContent) public XamlDocumentVisitor(IUnresolvedFile file, ITextSource fileContent)
{ {
this.file = file; this.file = file;
textDocument = new ReadOnlyDocument(fileContent); textDocument = new ReadOnlyDocument(fileContent, file.FileName);
} }
public override void VisitDocument(AXmlDocument document) public override void VisitDocument(AXmlDocument document)

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs

@ -82,7 +82,7 @@ namespace ICSharpCode.XamlBinding
int index = comment.Value.IndexOfAny(TaskListTokens, 0, out matchLength); int index = comment.Value.IndexOfAny(TaskListTokens, 0, out matchLength);
if (index > -1) { if (index > -1) {
if (document == null) if (document == null)
document = fileContent as IDocument ?? new ReadOnlyDocument(fileContent); document = fileContent as IDocument ?? new ReadOnlyDocument(fileContent, parseInfo.FileName);
do { do {
TextLocation startLocation = document.GetLocation(comment.StartOffset + index); TextLocation startLocation = document.GetLocation(comment.StartOffset + index);
int startOffset = index + comment.StartOffset; int startOffset = index + comment.StartOffset;

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs

@ -38,7 +38,7 @@ namespace ICSharpCode.XamlBinding
this.parseInfo = parseInfo; this.parseInfo = parseInfo;
this.location = location; this.location = location;
this.compilation = compilation; this.compilation = compilation;
textDocument = new ReadOnlyDocument(parseInfo.Text); textDocument = new ReadOnlyDocument(parseInfo.Text, parseInfo.FileName);
offset = textDocument.GetOffset(location); offset = textDocument.GetOffset(location);
AXmlObject innermost = parseInfo.Document.GetChildAtOffset(offset); AXmlObject innermost = parseInfo.Document.GetChildAtOffset(offset);

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlSymbolSearch.cs

@ -92,7 +92,7 @@ namespace ICSharpCode.XamlBinding
XamlResolver resolver = new XamlResolver(); XamlResolver resolver = new XamlResolver();
do { do {
if (document == null) { if (document == null) {
document = new ReadOnlyDocument(textSource); document = new ReadOnlyDocument(textSource, fileName);
highlighter = SD.EditorControlService.CreateHighlighter(document); highlighter = SD.EditorControlService.CreateHighlighter(document);
} }
var result = resolver.Resolve(parseInfo, document.GetLocation(offset + entity.Name.Length / 2 + 1), compilation, cancellationToken); var result = resolver.Resolve(parseInfo, document.GetLocation(offset + entity.Name.Length / 2 + 1), compilation, cancellationToken);

2
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) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using ICSharpCode.AvalonEdit.AddIn.Options; using ICSharpCode.AvalonEdit.AddIn.Options;
@ -33,6 +34,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
public IHighlighter CreateHighlighter(IDocument document) 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 def = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(document.FileName));
var doc = document as TextDocument; var doc = document as TextDocument;
if (def == null || doc == null) if (def == null || doc == null)

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ChangeMarkerMargin.cs

@ -230,7 +230,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
differ.editor.Visibility = Visibility.Collapsed; differ.editor.Visibility = Visibility.Collapsed;
differ.copyButton.Visibility = Visibility.Collapsed; differ.copyButton.Visibility = Visibility.Collapsed;
} else { } else {
var baseDocument = new ReadOnlyDocument(changeWatcher.BaseDocument); var baseDocument = new ReadOnlyDocument(changeWatcher.BaseDocument, TextView.Document.FileName);
if (differ.editor.SyntaxHighlighting != null) { if (differ.editor.SyntaxHighlighting != null) {
var mainHighlighter = new DocumentHighlighter(baseDocument, differ.editor.SyntaxHighlighting); var mainHighlighter = new DocumentHighlighter(baseDocument, differ.editor.SyntaxHighlighting);
var popupHighlighter = differ.editor.TextArea.GetService(typeof(IHighlighter)) as DocumentHighlighter; var popupHighlighter = differ.editor.TextArea.GetService(typeof(IHighlighter)) as DocumentHighlighter;

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs

@ -75,7 +75,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
Stream baseFileStream = GetBaseVersion(fileName); Stream baseFileStream = GetBaseVersion(fileName);
if (baseFileStream != null) { if (baseFileStream != null) {
// ReadAll() is taking care of closing the stream // ReadAll() is taking care of closing the stream
baseDocument = new ReadOnlyDocument(ReadAll(baseFileStream)); baseDocument = new ReadOnlyDocument(ReadAll(baseFileStream), fileName);
} else { } else {
// if the file is not under subversion, the document is the opened document // if the file is not under subversion, the document is the opened document
if (baseDocument == null) { if (baseDocument == null) {

2
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) 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 highlightingDefinition = HighlightingManager.Instance.GetDefinition("C#");
var block = DocumentPrinter.ConvertTextDocumentToBlock(document, highlightingDefinition); var block = DocumentPrinter.ConvertTextDocumentToBlock(document, highlightingDefinition);

2
src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs

@ -300,7 +300,7 @@ namespace SearchAndReplace
} }
// try to find a result // try to find a result
result = Find(file, new ReadOnlyDocument(buffer), searchOffset, length); result = Find(file, new ReadOnlyDocument(buffer, file), searchOffset, length);
i++; i++;
} }

10
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs

@ -81,17 +81,19 @@ namespace ICSharpCode.AvalonEdit.Document
/// Create an empty text document. /// Create an empty text document.
/// </summary> /// </summary>
public TextDocument() public TextDocument()
: this(string.Empty) : this("", "")
{ {
} }
/// <summary> /// <summary>
/// Create a new text document with the specified initial text. /// Create a new text document with the specified initial text.
/// </summary> /// </summary>
public TextDocument(IEnumerable<char> initialText, string fileName = null) public TextDocument(IEnumerable<char> initialText, string fileName)
{ {
if (initialText == null) if (initialText == null)
throw new ArgumentNullException("initialText"); throw new ArgumentNullException("initialText");
if (fileName == null)
throw new ArgumentNullException("fileName");
rope = new Rope<char>(initialText); rope = new Rope<char>(initialText);
lineTree = new DocumentLineTree(this); lineTree = new DocumentLineTree(this);
lineManager = new LineManager(lineTree, this); lineManager = new LineManager(lineTree, this);
@ -108,7 +110,7 @@ namespace ICSharpCode.AvalonEdit.Document
/// <summary> /// <summary>
/// Create a new text document with the specified initial text. /// Create a new text document with the specified initial text.
/// </summary> /// </summary>
public TextDocument(ITextSource initialText, string fileName = null) public TextDocument(ITextSource initialText, string fileName)
: this(GetTextFromTextSource(initialText), fileName) : this(GetTextFromTextSource(initialText), fileName)
{ {
} }
@ -351,7 +353,7 @@ namespace ICSharpCode.AvalonEdit.Document
/// <inheritdoc/> /// <inheritdoc/>
public IDocument CreateDocumentSnapshot() public IDocument CreateDocumentSnapshot()
{ {
return new ReadOnlyDocument(this); return new ReadOnlyDocument(this, fileName);
} }
/// <inheritdoc/> /// <inheritdoc/>

6
src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/ReadOnlyDocument.cs

@ -36,10 +36,12 @@ namespace ICSharpCode.NRefactory.Editor
/// <summary> /// <summary>
/// Creates a new ReadOnlyDocument from the given text source. /// Creates a new ReadOnlyDocument from the given text source.
/// </summary> /// </summary>
public ReadOnlyDocument(ITextSource textSource, string fileName = null) public ReadOnlyDocument(ITextSource textSource, string fileName)
{ {
if (textSource == null) if (textSource == null)
throw new ArgumentNullException("textSource"); throw new ArgumentNullException("textSource");
if (fileName == null)
throw new ArgumentNullException("fileName");
// ensure that underlying buffer is immutable // ensure that underlying buffer is immutable
this.textSource = textSource.CreateSnapshot(); this.textSource = textSource.CreateSnapshot();
this.fileName = fileName; this.fileName = fileName;
@ -60,7 +62,7 @@ namespace ICSharpCode.NRefactory.Editor
/// <summary> /// <summary>
/// Creates a new ReadOnlyDocument from the given string. /// Creates a new ReadOnlyDocument from the given string.
/// </summary> /// </summary>
public ReadOnlyDocument(string text, string fileName = null) public ReadOnlyDocument(string text, string fileName)
: this(new StringTextSource(text), fileName) : this(new StringTextSource(text), fileName)
{ {
} }

2
src/Libraries/NRefactory/ICSharpCode.NRefactory/Editor/StringBuilderDocument.cs

@ -262,7 +262,7 @@ namespace ICSharpCode.NRefactory.Editor
public IDocument CreateDocumentSnapshot() public IDocument CreateDocumentSnapshot()
{ {
if (documentSnapshot == null) if (documentSnapshot == null)
documentSnapshot = new ReadOnlyDocument(this); documentSnapshot = new ReadOnlyDocument(this, string.Empty);
return documentSnapshot; return documentSnapshot;
} }

4
src/Main/Base/Project/Src/Editor/DocumentUtilitites.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.SharpDevelop.Editor
[Obsolete("Use the TextDocument constructor instead")] [Obsolete("Use the TextDocument constructor instead")]
public static IDocument LoadDocumentFromBuffer(ITextSource buffer) public static IDocument LoadDocumentFromBuffer(ITextSource buffer)
{ {
return new TextDocument(buffer); return new TextDocument(buffer, null);
} }
/// <summary> /// <summary>
@ -35,7 +35,7 @@ namespace ICSharpCode.SharpDevelop.Editor
[Obsolete("Use the ReadOnlyDocument constructor instead")] [Obsolete("Use the ReadOnlyDocument constructor instead")]
public static IDocument LoadReadOnlyDocumentFromBuffer(ITextSource buffer) public static IDocument LoadReadOnlyDocumentFromBuffer(ITextSource buffer)
{ {
return new ReadOnlyDocument(buffer); return new ReadOnlyDocument(buffer, null);
} }
/// <summary> /// <summary>

2
src/Main/Base/Project/Src/Gui/Pads/DefinitionViewPad.cs

@ -127,7 +127,7 @@ namespace ICSharpCode.SharpDevelop.Gui
void LoadFile(string fileName) void LoadFile(string fileName)
{ {
// Load the text into the definition view's text editor. // 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; currentFileName = fileName;
ctl.SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName)); ctl.SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName));
} }

2
src/Main/SharpDevelop/Workbench/WorkbenchStartup.cs

@ -142,7 +142,7 @@ class Test {
void Main(string[] b) { void Main(string[] b) {
SomeMethod(b[0 + 1]); SomeMethod(b[0 + 1]);
} }
}"), "test.cs"); }", "test.cs"), "test.cs");
// warm up the type system // warm up the type system
var unresolvedFile = cu.ToTypeSystem(); var unresolvedFile = cu.ToTypeSystem();
var pc = new ICSharpCode.NRefactory.CSharp.CSharpProjectContent().AddOrUpdateFiles(unresolvedFile); var pc = new ICSharpCode.NRefactory.CSharp.CSharpProjectContent().AddOrUpdateFiles(unresolvedFile);

Loading…
Cancel
Save