Browse Source

implement IParser.GetFileContent: allows the ParserService to work with "files" that are not written to disk

pull/80/head
Siegfried Pammer 12 years ago
parent
commit
9b5fec399d
  1. 5
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs
  2. 4
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs
  3. 9
      src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyParser.cs
  4. 6
      src/Main/Base/Project/Parser/IParser.cs
  5. 2
      src/Main/SharpDevelop/Parser/ParserService.cs
  6. 6
      src/Main/SharpDevelop/Parser/ParserServiceEntry.cs

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

@ -68,6 +68,11 @@ namespace CSharpBinding.Parser
} }
*/ */
public ITextSource GetFileContent(FileName fileName)
{
return SD.FileService.GetFileContent(fileName);
}
public ParseInformation Parse(FileName fileName, ITextSource fileContent, bool fullParseInformationRequested, public ParseInformation Parse(FileName fileName, ITextSource fileContent, bool fullParseInformationRequested,
IProject parentProject, CancellationToken cancellationToken) IProject parentProject, CancellationToken cancellationToken)
{ {

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

@ -39,9 +39,9 @@ namespace ICSharpCode.XamlBinding
return Path.GetExtension(fileName).Equals(".xaml", StringComparison.OrdinalIgnoreCase); return Path.GetExtension(fileName).Equals(".xaml", StringComparison.OrdinalIgnoreCase);
} }
public bool CanParse(IProject project) public ITextSource GetFileContent(FileName fileName)
{ {
return false; return SD.FileService.GetFileContent(fileName);
} }
volatile IncrementalParserState parserState; volatile IncrementalParserState parserState;

9
src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyParser.cs

@ -32,6 +32,13 @@ namespace ICSharpCode.ILSpyAddIn
return fileName != null && fileName.StartsWith("ilspy://", StringComparison.OrdinalIgnoreCase); return fileName != null && fileName.StartsWith("ilspy://", StringComparison.OrdinalIgnoreCase);
} }
readonly static ITextSource EmptyFileContent = new StringTextSource("");
public ITextSource GetFileContent(FileName fileName)
{
return EmptyFileContent;
}
public ParseInformation Parse(FileName fileName, ITextSource fileContent, bool fullParseInformationRequested, IProject parentProject, CancellationToken cancellationToken) public ParseInformation Parse(FileName fileName, ITextSource fileContent, bool fullParseInformationRequested, IProject parentProject, CancellationToken cancellationToken)
{ {
return ILSpyDecompilerService.DecompileType(DecompiledTypeReference.FromFileName(fileName), cancellationToken); return ILSpyDecompilerService.DecompileType(DecompiledTypeReference.FromFileName(fileName), cancellationToken);
@ -41,7 +48,7 @@ namespace ICSharpCode.ILSpyAddIn
{ {
var decompiledParseInfo = parseInfo as ILSpyFullParseInformation; var decompiledParseInfo = parseInfo as ILSpyFullParseInformation;
if (decompiledParseInfo == null) if (decompiledParseInfo == null)
throw new ArgumentException("Parse info does not have SyntaxTree"); throw new ArgumentException("ParseInfo does not have SyntaxTree");
return ResolveAtLocation.Resolve(compilation, null, decompiledParseInfo.SyntaxTree, location, cancellationToken); return ResolveAtLocation.Resolve(compilation, null, decompiledParseInfo.SyntaxTree, location, cancellationToken);
} }

6
src/Main/Base/Project/Parser/IParser.cs

@ -34,10 +34,14 @@ namespace ICSharpCode.SharpDevelop.Parser
/// </summary> /// </summary>
bool CanParse(string fileName); bool CanParse(string fileName);
/// <summary>
/// Returns the content for a given filename.
/// </summary>
ITextSource GetFileContent(FileName fileName);
/// <summary> /// <summary>
/// Parses a file. /// Parses a file.
/// </summary> /// </summary>
/// <param name="projectContent">The parent project of the file.</param>
/// <param name="fileName">The name of the file being parsed.</param> /// <param name="fileName">The name of the file being parsed.</param>
/// <param name="fileContent">The content of the file.</param> /// <param name="fileContent">The content of the file.</param>
/// <param name="fullParseInformationRequested"> /// <param name="fullParseInformationRequested">

2
src/Main/SharpDevelop/Parser/ParserService.cs

@ -315,7 +315,7 @@ namespace ICSharpCode.SharpDevelop.Parser
if (entry.parser == null) if (entry.parser == null)
return; return;
if (fileContent == null) if (fileContent == null)
fileContent = SD.FileService.GetFileContent(fileName); fileContent = entry.parser.GetFileContent(fileName);
if (compilation == null) if (compilation == null)
compilation = GetCompilationForFile(fileName); compilation = GetCompilationForFile(fileName);
var parseInfo = await entry.ParseAsync(fileContent, compilation.GetProject(), cancellationToken).ConfigureAwait(false); var parseInfo = await entry.ParseAsync(fileContent, compilation.GetProject(), cancellationToken).ConfigureAwait(false);

6
src/Main/SharpDevelop/Parser/ParserServiceEntry.cs

@ -167,7 +167,7 @@ namespace ICSharpCode.SharpDevelop.Parser
public ParseInformation Parse(ITextSource fileContent, IProject parentProject, CancellationToken cancellationToken) public ParseInformation Parse(ITextSource fileContent, IProject parentProject, CancellationToken cancellationToken)
{ {
if (fileContent == null) { if (fileContent == null) {
fileContent = SD.FileService.GetFileContent(fileName); fileContent = parser.GetFileContent(fileName);
} }
return DoParse(fileContent, parentProject, true, cancellationToken).CachedParseInformation; return DoParse(fileContent, parentProject, true, cancellationToken).CachedParseInformation;
@ -176,7 +176,7 @@ namespace ICSharpCode.SharpDevelop.Parser
public IUnresolvedFile ParseFile(ITextSource fileContent, IProject parentProject, CancellationToken cancellationToken) public IUnresolvedFile ParseFile(ITextSource fileContent, IProject parentProject, CancellationToken cancellationToken)
{ {
if (fileContent == null) { if (fileContent == null) {
fileContent = SD.FileService.GetFileContent(fileName); fileContent = parser.GetFileContent(fileName);
} }
return DoParse(fileContent, parentProject, false, cancellationToken).UnresolvedFile; return DoParse(fileContent, parentProject, false, cancellationToken).UnresolvedFile;
@ -302,7 +302,7 @@ namespace ICSharpCode.SharpDevelop.Parser
// Let's look up the file in the list of open files right now // Let's look up the file in the list of open files right now
// so that we don't need to SafeThreadCall() later on. // so that we don't need to SafeThreadCall() later on.
lookupOpenFileOnTargetThread = false; lookupOpenFileOnTargetThread = false;
fileContent = SD.FileService.GetFileContentForOpenFile(fileName); fileContent = parser.GetFileContent(fileName);
} }
Task<ProjectEntry> task; Task<ProjectEntry> task;
lock (this) { lock (this) {

Loading…
Cancel
Save