-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #659 from filipw/feature/scripting-revamp
Scripting revamp
- Loading branch information
Showing
13 changed files
with
192 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
|
||
namespace OmniSharp.Script | ||
{ | ||
public class FileParser | ||
{ | ||
public static FileParserResult ProcessFile(string path, CSharpParseOptions parseOptions) | ||
{ | ||
var result = new FileParserResult(); | ||
ParseFile(path, result, parseOptions); | ||
return result; | ||
} | ||
|
||
private static void ParseFile(string path, FileParserResult result, CSharpParseOptions parseOptions) | ||
{ | ||
var fullPath = Path.GetFullPath(path); | ||
if (result.LoadedScripts.Contains(fullPath)) | ||
{ | ||
return; | ||
} | ||
|
||
result.LoadedScripts.Add(fullPath); | ||
|
||
var scriptCode = File.ReadAllText(fullPath); | ||
|
||
var syntaxTree = CSharpSyntaxTree.ParseText(scriptCode, parseOptions); | ||
|
||
var namespaces = syntaxTree.GetCompilationUnitRoot().Usings.Select(x => x.Name.ToString()); | ||
foreach (var ns in namespaces) | ||
{ | ||
result.Namespaces.Add(ns.Trim()); | ||
} | ||
|
||
var refs = syntaxTree.GetCompilationUnitRoot().GetReferenceDirectives().Select(x => x.File.ToString()); | ||
foreach (var reference in refs) | ||
{ | ||
result.References.Add(reference.Replace("\"", string.Empty)); | ||
} | ||
|
||
var loads = syntaxTree.GetCompilationUnitRoot().GetLoadDirectives().Select(x => x.File.ToString()); | ||
foreach (var load in loads) | ||
{ | ||
var filePath = load.Replace("\"", string.Empty); | ||
var currentWorkingDirectory = Path.GetDirectoryName(fullPath); | ||
|
||
var loadFullPath = Path.IsPathRooted(filePath) ? filePath : Path.Combine(currentWorkingDirectory, filePath); | ||
if (!string.IsNullOrWhiteSpace(loadFullPath)) | ||
{ | ||
ParseFile(loadFullPath, result, parseOptions); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace OmniSharp.Script | ||
{ | ||
public class FileParserResult | ||
{ | ||
public HashSet<string> Namespaces { get; } = new HashSet<string>(); | ||
public HashSet<string> References { get; } = new HashSet<string>(); | ||
public HashSet<string> LoadedScripts { get; } = new HashSet<string>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 6 additions & 9 deletions
15
src/OmniSharp.ScriptCs/ScriptCsContext.cs → src/OmniSharp.Script/ScriptContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Composition; | ||
using System.Reflection; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace OmniSharp.ScriptCs | ||
namespace OmniSharp.Script | ||
{ | ||
[Export, Shared] | ||
public class ScriptCsContext | ||
public class ScriptContext | ||
{ | ||
public HashSet<string> CsxFilesBeingProcessed { get; } = new HashSet<string>(); | ||
|
||
// All of the followings are keyed with the file path | ||
// Each .csx file is wrapped into a project | ||
public Dictionary<string, ProjectInfo> CsxFileProjects { get; } = new Dictionary<string, ProjectInfo>(); | ||
public Dictionary<string, List<MetadataReference>> CsxReferences { get; } = new Dictionary<string, List<MetadataReference>>(); | ||
public Dictionary<string, List<PortableExecutableReference>> CsxReferences { get; } = new Dictionary<string, List<PortableExecutableReference>>(); | ||
public Dictionary<string, List<ProjectInfo>> CsxLoadReferences { get; } = new Dictionary<string, List<ProjectInfo>>(); | ||
public Dictionary<string, List<string>> CsxUsings { get; } = new Dictionary<string, List<string>>(); | ||
|
||
public HashSet<string> ScriptPacks { get; } = new HashSet<string>(); | ||
|
||
// Nuget and ScriptPack stuff | ||
public HashSet<MetadataReference> CommonReferences { get; } = new HashSet<MetadataReference>(); | ||
public HashSet<string> CommonUsings { get; } = new HashSet<string>(); | ||
|
||
public HashSet<string> CommonUsings { get; } = new HashSet<string> { "System" }; | ||
public string RootPath { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.