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 @@ -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,
IProject parentProject, CancellationToken cancellationToken)
{

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

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

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

@ -32,6 +32,13 @@ namespace ICSharpCode.ILSpyAddIn @@ -32,6 +32,13 @@ namespace ICSharpCode.ILSpyAddIn
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)
{
return ILSpyDecompilerService.DecompileType(DecompiledTypeReference.FromFileName(fileName), cancellationToken);
@ -41,7 +48,7 @@ namespace ICSharpCode.ILSpyAddIn @@ -41,7 +48,7 @@ namespace ICSharpCode.ILSpyAddIn
{
var decompiledParseInfo = parseInfo as ILSpyFullParseInformation;
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);
}

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

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

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

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

Loading…
Cancel
Save