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 @@ -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;

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

@ -87,12 +87,12 @@ namespace CSharpBinding.Parser @@ -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<TagComment> tagComments, ITextSource fileContent)
void AddCommentTags(SyntaxTree cu, IList<TagComment> tagComments, ITextSource fileContent, FileName fileName)
{
ReadOnlyDocument document = null;
foreach (var comment in cu.Descendants.OfType<Comment>().Where(c => c.CommentType != CommentType.InactiveCode)) {
@ -100,7 +100,7 @@ namespace CSharpBinding.Parser @@ -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 @@ -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);

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

@ -108,21 +108,21 @@ namespace CSharpBinding.Refactoring @@ -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);
}

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

@ -121,7 +121,7 @@ namespace ICSharpCode.XamlBinding @@ -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)

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

@ -82,7 +82,7 @@ namespace ICSharpCode.XamlBinding @@ -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;

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

@ -38,7 +38,7 @@ namespace ICSharpCode.XamlBinding @@ -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);

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

@ -92,7 +92,7 @@ namespace ICSharpCode.XamlBinding @@ -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);

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

@ -2,6 +2,7 @@ @@ -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 @@ -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)

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

@ -230,7 +230,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -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;

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

@ -75,7 +75,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -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) {

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/XmlDoc/DocumentationUIBuilder.cs

@ -200,7 +200,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.XmlDoc @@ -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);

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

@ -300,7 +300,7 @@ namespace SearchAndReplace @@ -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++;
}

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

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

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

@ -36,10 +36,12 @@ namespace ICSharpCode.NRefactory.Editor @@ -36,10 +36,12 @@ namespace ICSharpCode.NRefactory.Editor
/// <summary>
/// Creates a new ReadOnlyDocument from the given text source.
/// </summary>
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 @@ -60,7 +62,7 @@ namespace ICSharpCode.NRefactory.Editor
/// <summary>
/// Creates a new ReadOnlyDocument from the given string.
/// </summary>
public ReadOnlyDocument(string text, string fileName = null)
public ReadOnlyDocument(string text, string fileName)
: this(new StringTextSource(text), fileName)
{
}

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

@ -262,7 +262,7 @@ namespace ICSharpCode.NRefactory.Editor @@ -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;
}

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

@ -26,7 +26,7 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -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);
}
/// <summary>
@ -35,7 +35,7 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -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);
}
/// <summary>

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

@ -127,7 +127,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -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));
}

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

@ -142,7 +142,7 @@ class Test { @@ -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);

Loading…
Cancel
Save