Skip to content

Commit 200aaf6

Browse files
committed
Merge pull request #18 from PowerShell/demo
Introducing basic file reference traversal support
2 parents 5b88e06 + 9de1f3a commit 200aaf6

38 files changed

+978
-320
lines changed

src/PowerShellEditorServices.Host/Program.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Program
1616
[STAThread]
1717
static void Main(string[] args)
1818
{
19+
#if DEBUG
1920
// In the future, a more robust argument parser will be added here
2021
bool waitForDebugger =
2122
args.Any(
@@ -28,11 +29,15 @@ static void Main(string[] args)
2829
// Should we wait for the debugger before starting?
2930
if (waitForDebugger)
3031
{
31-
while (!Debugger.IsAttached)
32+
// Wait for 15 seconds and then continue
33+
int waitCountdown = 15;
34+
while (!Debugger.IsAttached && waitCountdown > 0)
3235
{
33-
Thread.Sleep(500);
36+
Thread.Sleep(1000);
37+
waitCountdown--;
3438
}
3539
}
40+
#endif
3641

3742
// TODO: Select host, console host, and transport based on command line arguments
3843

src/PowerShellEditorServices.Transport.Stdio/Event/DiagnosticEvent.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public static DiagnosticEventBody Create(
6161
new Diagnostic
6262
{
6363
Text = diagnosticMarker.Message,
64+
Severity = (int)diagnosticMarker.Level + 1,
6465
Start = new Location
6566
{
6667
Line = diagnosticMarker.ScriptRegion.StartLineNumber,
@@ -97,5 +98,7 @@ public class Diagnostic
9798
public Location End { get; set; }
9899

99100
public string Text { get; set; }
101+
102+
public int Severity { get; set; }
100103
}
101104
}

src/PowerShellEditorServices.Transport.Stdio/Request/DeclarationRequest.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,31 @@ public override void ProcessMessage(
1818
MessageWriter messageWriter)
1919
{
2020
ScriptFile scriptFile = this.GetScriptFile(editorSession);
21-
22-
GetDefinitionResult definition =
23-
editorSession.LanguageService.GetDefinitionInFile(
21+
SymbolReference foundSymbol =
22+
editorSession.LanguageService.FindSymbolAtLocation(
2423
scriptFile,
2524
this.Arguments.Line,
2625
this.Arguments.Offset);
27-
28-
if (definition != null)
26+
27+
GetDefinitionResult definition = null;
28+
if (foundSymbol != null)
2929
{
30-
DefinitionResponse defResponse =
31-
DefinitionResponse.Create(definition.FoundDefinition, this.Arguments.File);
30+
definition =
31+
editorSession.LanguageService.GetDefinitionOfSymbol(
32+
scriptFile,
33+
foundSymbol,
34+
editorSession.Workspace);
35+
36+
}
3237

33-
messageWriter.WriteMessage(
34-
this.PrepareResponse(defResponse));
38+
DefinitionResponse defResponse = DefinitionResponse.Create();
39+
if (definition != null && definition.FoundDefinition != null)
40+
{
41+
defResponse = DefinitionResponse.Create(definition.FoundDefinition);
3542
}
43+
44+
messageWriter.WriteMessage(
45+
this.PrepareResponse(defResponse));
3646
}
3747
}
3848
}

src/PowerShellEditorServices.Transport.Stdio/Request/ErrorRequest.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,9 @@ public override void ProcessMessage(
3333
// Get the requested files
3434
foreach (string filePath in this.Arguments.Files)
3535
{
36-
ScriptFile scriptFile = null;
37-
38-
if (!editorSession.TryGetFile(filePath, out scriptFile))
39-
{
40-
// Skip this file and log the file load error
41-
// TODO: Trace out the error message
42-
continue;
43-
}
36+
ScriptFile scriptFile =
37+
editorSession.Workspace.GetFile(
38+
filePath);
4439

4540
var semanticMarkers =
4641
editorSession.AnalysisService.GetSemanticMarkers(

src/PowerShellEditorServices.Transport.Stdio/Request/FileRequest.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,9 @@ public abstract class FileRequest<TArguments> : RequestBase<TArguments>
1313
{
1414
protected ScriptFile GetScriptFile(EditorSession editorSession)
1515
{
16-
ScriptFile scriptFile = null;
17-
18-
if(!editorSession.TryGetFile(
19-
this.Arguments.File,
20-
out scriptFile))
21-
{
22-
// TODO: Throw an exception that the message loop can create a response out of
23-
24-
throw new FileNotFoundException(
25-
"A ScriptFile with the following path was not found in the EditorSession: {0}",
16+
return
17+
editorSession.Workspace.GetFile(
2618
this.Arguments.File);
27-
}
28-
29-
return scriptFile;
3019
}
3120
}
3221

src/PowerShellEditorServices.Transport.Stdio/Request/OpenFileRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override void ProcessMessage(
2727
MessageWriter messageWriter)
2828
{
2929
// Open the file in the current session
30-
editorSession.OpenFile(this.Arguments.File);
30+
editorSession.Workspace.GetFile(this.Arguments.File);
3131
}
3232
}
3333
}

src/PowerShellEditorServices.Transport.Stdio/Request/ReferencesRequest.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ public override void ProcessMessage(
1818
MessageWriter messageWriter)
1919
{
2020
ScriptFile scriptFile = this.GetScriptFile(editorSession);
21-
22-
FindReferencesResult referencesResult =
23-
editorSession.LanguageService.FindReferencesInFile(
21+
SymbolReference foundSymbol =
22+
editorSession.LanguageService.FindSymbolAtLocation(
2423
scriptFile,
2524
this.Arguments.Line,
2625
this.Arguments.Offset);
2726

27+
FindReferencesResult referencesResult =
28+
editorSession.LanguageService.FindReferencesOfSymbol(
29+
foundSymbol,
30+
editorSession.Workspace.ExpandScriptReferences(scriptFile));
31+
2832
ReferencesResponse referencesResponse =
2933
ReferencesResponse.Create(referencesResult, this.Arguments.File);
3034

src/PowerShellEditorServices.Transport.Stdio/Response/DefinitionResponse.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Microsoft.PowerShell.EditorServices.Transport.Stdio.Response
1212
[MessageTypeName("definition")]
1313
public class DefinitionResponse : ResponseBase<FileSpan[]>
1414
{
15-
public static DefinitionResponse Create(SymbolReference result, string thisFile)
15+
public static DefinitionResponse Create(SymbolReference result)
1616
{
1717
if (result != null)
1818
{
@@ -31,7 +31,7 @@ public static DefinitionResponse Create(SymbolReference result, string thisFile)
3131
Line = result.ScriptRegion.EndLineNumber,
3232
Offset = result.ScriptRegion.EndColumnNumber
3333
},
34-
File = thisFile,
34+
File = result.FilePath
3535
});
3636
return new DefinitionResponse
3737
{
@@ -46,5 +46,12 @@ public static DefinitionResponse Create(SymbolReference result, string thisFile)
4646
};
4747
}
4848
}
49+
public static DefinitionResponse Create()
50+
{
51+
return new DefinitionResponse
52+
{
53+
Body = null
54+
};
55+
}
4956
}
5057
}

src/PowerShellEditorServices.Transport.Stdio/Response/ReferencesResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ List<ReferencesResponseItem> referenceItems
3535
Offset = reference.ScriptRegion.EndColumnNumber
3636
},
3737
IsWriteAccess = true,
38-
File = thisFile,
38+
File = reference.FilePath,
3939
LineText = reference.SourceLine
4040
});
4141
}

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public AnalysisService(Runspace analysisRunspace)
4040
this.scriptAnalyzer = new ScriptAnalyzer();
4141
this.scriptAnalyzer.Initialize(
4242
analysisRunspace,
43-
new AnalysisOutputWriter());
43+
new AnalysisOutputWriter(),
44+
null,
45+
null,
46+
new string[] { "DscTestsPresent", "DscExamplesPresent" });
4447
}
4548

4649
#endregion
@@ -55,26 +58,34 @@ public AnalysisService(Runspace analysisRunspace)
5558
/// <returns>An array of ScriptFileMarkers containing semantic analysis results.</returns>
5659
public ScriptFileMarker[] GetSemanticMarkers(ScriptFile file)
5760
{
58-
// TODO: This is a temporary fix until we can change how
59-
// ScriptAnalyzer invokes their async tasks.
60-
Task<ScriptFileMarker[]> analysisTask =
61-
Task.Factory.StartNew<ScriptFileMarker[]>(
62-
() =>
63-
{
64-
return
65-
this.scriptAnalyzer
66-
.AnalyzeSyntaxTree(
67-
file.ScriptAst,
68-
file.ScriptTokens,
69-
file.FilePath)
70-
.Select(ScriptFileMarker.FromDiagnosticRecord)
71-
.ToArray();
72-
},
73-
CancellationToken.None,
74-
TaskCreationOptions.None,
75-
TaskScheduler.Default);
61+
if (file.IsAnalysisEnabled)
62+
{
63+
// TODO: This is a temporary fix until we can change how
64+
// ScriptAnalyzer invokes their async tasks.
65+
Task<ScriptFileMarker[]> analysisTask =
66+
Task.Factory.StartNew<ScriptFileMarker[]>(
67+
() =>
68+
{
69+
return
70+
this.scriptAnalyzer
71+
.AnalyzeSyntaxTree(
72+
file.ScriptAst,
73+
file.ScriptTokens,
74+
file.FilePath)
75+
.Select(ScriptFileMarker.FromDiagnosticRecord)
76+
.ToArray();
77+
},
78+
CancellationToken.None,
79+
TaskCreationOptions.None,
80+
TaskScheduler.Default);
7681

77-
return analysisTask.Result;
82+
return analysisTask.Result;
83+
}
84+
else
85+
{
86+
// Return an empty marker list
87+
return new ScriptFileMarker[0];
88+
}
7889
}
7990

8091
#endregion

0 commit comments

Comments
 (0)