-
Notifications
You must be signed in to change notification settings - Fork 418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scripting revamp #659
Merged
DustinCampbell
merged 11 commits into
OmniSharp:dev
from
filipw:feature/scripting-revamp
Nov 24, 2016
Merged
Scripting revamp #659
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b886ff5
remove scriptcs
filipw ba285b8
folder rename
filipw a5dbed5
scripting WIP
filipw e5c92d5
updated file parsing logic
filipw 7d4c7e4
general clean up
filipw 83ba62f
added scriptcs attribution
filipw 46e88d7
better file parsing and overall logic
filipw 7df0560
some extra scripting reference logic
filipw 5f22e94
updated to roslyn 2.0.0-rc
filipw 11f9e10
applied code review feedback
filipw 9c45a68
fixed build
filipw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work on OSX/Linux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this just strips away the quotes, tested on Mac too. when I have i.e.
#load "bar.csx"
in my CSX and I useGetXXXDirectives()
method on the compilation root, the result string comes back with quotes inside i.e."bar.csx"
notbar.csx
and I want to strip it away to be able to concat the relative path and traverse these resourcesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry. I misread the slash in there. :-) I glanced at it and read the slash, not the double-quote. 😄