public void LanguageServiceFindsSymbolsInFile() { FindOccurrencesResult symbolsResult = this.FindSymbolsInFile( FindSymbolsInMultiSymbolFile.SourceDetails); Assert.Equal(4, symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Function).Count()); Assert.Equal(3, symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Variable).Count()); Assert.Equal(1, symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Workflow).Count()); SymbolReference firstFunctionSymbol = symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Function).First(); Assert.Equal("AFunction", firstFunctionSymbol.SymbolName); Assert.Equal(7, firstFunctionSymbol.ScriptRegion.StartLineNumber); Assert.Equal(1, firstFunctionSymbol.ScriptRegion.StartColumnNumber); SymbolReference lastVariableSymbol = symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Variable).Last(); Assert.Equal("$Script:ScriptVar2", lastVariableSymbol.SymbolName); Assert.Equal(3, lastVariableSymbol.ScriptRegion.StartLineNumber); Assert.Equal(1, lastVariableSymbol.ScriptRegion.StartColumnNumber); SymbolReference firstWorkflowSymbol = symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Workflow).First(); Assert.Equal("AWorkflow", firstWorkflowSymbol.SymbolName); Assert.Equal(23, firstWorkflowSymbol.ScriptRegion.StartLineNumber); Assert.Equal(1, firstWorkflowSymbol.ScriptRegion.StartColumnNumber); // TODO: Bring this back when we can use AstVisitor2 again (#276) //Assert.Equal(1, symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Configuration).Count()); //SymbolReference firstConfigurationSymbol = symbolsResult.FoundOccurrences.Where(r => r.SymbolType == SymbolType.Configuration).First(); //Assert.Equal("AConfiguration", firstConfigurationSymbol.SymbolName); //Assert.Equal(25, firstConfigurationSymbol.ScriptRegion.StartLineNumber); //Assert.Equal(1, firstConfigurationSymbol.ScriptRegion.StartColumnNumber); }
public void LanguageServiceFindsSymbolsInNoSymbolsFile() { FindOccurrencesResult symbolsResult = this.FindSymbolsInFile( FindSymbolsInNoSymbolsFile.SourceDetails); Assert.Equal(0, symbolsResult.FoundOccurrences.Count()); }
public void LanguageServiceFindsOccurrencesOnParameter() { FindOccurrencesResult occurrencesResult = this.GetOccurrences( FindOccurrencesOnParameter.SourceDetails); Assert.Equal("$myInput", occurrencesResult.FoundOccurrences.Last().SymbolName); Assert.Equal(2, occurrencesResult.FoundOccurrences.Count()); Assert.Equal(3, occurrencesResult.FoundOccurrences.Last().ScriptRegion.StartLineNumber); }
public void LanguageServiceFindsOccurrencesOnFunction() { FindOccurrencesResult occurrencesResult = this.GetOccurrences( FindsOccurrencesOnFunction.SourceDetails); Assert.Equal(3, occurrencesResult.FoundOccurrences.Count()); Assert.Equal(10, occurrencesResult.FoundOccurrences.Last().ScriptRegion.StartLineNumber); Assert.Equal(1, occurrencesResult.FoundOccurrences.Last().ScriptRegion.StartColumnNumber); }
protected async Task HandleDocumentSymbolRequest( TextDocumentIdentifier textDocumentIdentifier, EditorSession editorSession, RequestContext <SymbolInformation[], object> requestContext) { ScriptFile scriptFile = editorSession.Workspace.GetFile( textDocumentIdentifier.Uri); FindOccurrencesResult foundSymbols = editorSession.LanguageService.FindSymbolsInFile( scriptFile); SymbolInformation[] symbols = null; string containerName = Path.GetFileNameWithoutExtension(scriptFile.FilePath); if (foundSymbols != null) { symbols = foundSymbols .FoundOccurrences .Select(r => { return(new SymbolInformation { ContainerName = containerName, Kind = GetSymbolKind(r.SymbolType), Location = new Location { Uri = new Uri(r.FilePath).AbsolutePath, Range = GetRangeFromScriptRegion(r.ScriptRegion) }, Name = GetDecoratedSymbolName(r) }); }) .ToArray(); } else { symbols = new SymbolInformation[0]; } await requestContext.SendResult(symbols); }
protected async Task HandleWorkspaceSymbolRequest( WorkspaceSymbolParams workspaceSymbolParams, EditorSession editorSession, RequestContext <SymbolInformation[], object> requestContext) { var symbols = new List <SymbolInformation>(); foreach (ScriptFile scriptFile in editorSession.Workspace.GetOpenedFiles()) { FindOccurrencesResult foundSymbols = editorSession.LanguageService.FindSymbolsInFile( scriptFile); // TODO: Need to compute a relative path that is based on common path for all workspace files string containerName = Path.GetFileNameWithoutExtension(scriptFile.FilePath); if (foundSymbols != null) { var matchedSymbols = foundSymbols .FoundOccurrences .Where(r => IsQueryMatch(workspaceSymbolParams.Query, r.SymbolName)) .Select(r => { return(new SymbolInformation { ContainerName = containerName, Kind = r.SymbolType == SymbolType.Variable ? SymbolKind.Variable : SymbolKind.Function, Location = new Location { Uri = new Uri(r.FilePath).AbsoluteUri, Range = GetRangeFromScriptRegion(r.ScriptRegion) }, Name = GetDecoratedSymbolName(r) }); }); symbols.AddRange(matchedSymbols); } } await requestContext.SendResult(symbols.ToArray()); }
protected async Task HandleDocumentHighlightRequest( TextDocumentPosition textDocumentPosition, EditorSession editorSession, RequestContext <DocumentHighlight[], object> requestContext) { ScriptFile scriptFile = editorSession.Workspace.GetFile( textDocumentPosition.Uri); FindOccurrencesResult occurrencesResult = editorSession.LanguageService.FindOccurrencesInFile( scriptFile, textDocumentPosition.Position.Line + 1, textDocumentPosition.Position.Character + 1); DocumentHighlight[] documentHighlights = null; if (occurrencesResult != null) { documentHighlights = occurrencesResult .FoundOccurrences .Select(o => { return(new DocumentHighlight { Kind = DocumentHighlightKind.Write, // TODO: Which symbol types are writable? Range = GetRangeFromScriptRegion(o.ScriptRegion) }); }) .ToArray(); } else { documentHighlights = new DocumentHighlight[0]; } await requestContext.SendResult(documentHighlights); }