/// <summary> /// Take a codelens and create a new codelens object with updated references. /// </summary> /// <param name="codeLens">The old code lens to get updated references for.</param> /// <returns>A new code lens object describing the same data as the old one but with updated references.</returns> public CodeLens ResolveCodeLens(CodeLens codeLens, ScriptFile scriptFile) { ScriptFile[] references = _workspaceService.ExpandScriptReferences( scriptFile); SymbolReference foundSymbol = _symbolsService.FindFunctionDefinitionAtLocation( scriptFile, codeLens.Range.Start.Line + 1, codeLens.Range.Start.Character + 1); List <SymbolReference> referencesResult = _symbolsService.FindReferencesOfSymbol( foundSymbol, references, _workspaceService); Location[] referenceLocations; if (referencesResult == null) { referenceLocations = s_emptyLocationArray; } else { var acc = new List <Location>(); foreach (SymbolReference foundReference in referencesResult) { if (IsReferenceDefinition(foundSymbol, foundReference)) { continue; } acc.Add(new Location { Uri = DocumentUri.From(foundReference.FilePath), Range = foundReference.ScriptRegion.ToRange() }); } referenceLocations = acc.ToArray(); } return(new CodeLens { Data = codeLens.Data, Range = codeLens.Range, Command = new Command { Name = "editor.action.showReferences", Title = GetReferenceCountHeader(referenceLocations.Length), Arguments = JArray.FromObject(new object[] { scriptFile.DocumentUri, codeLens.Range.Start, referenceLocations }, Serializer.Instance.JsonSerializer) } }); }
/// <summary> /// Take a codelens and create a new codelens object with updated references. /// </summary> /// <param name="codeLens">The old code lens to get updated references for.</param> /// <param name="scriptFile"></param> /// <returns>A new code lens object describing the same data as the old one but with updated references.</returns> public async Task <CodeLens> ResolveCodeLens(CodeLens codeLens, ScriptFile scriptFile) { ScriptFile[] references = _workspaceService.ExpandScriptReferences( scriptFile); SymbolReference foundSymbol = SymbolsService.FindFunctionDefinitionAtLocation( scriptFile, codeLens.Range.Start.Line + 1, codeLens.Range.Start.Character + 1); List <SymbolReference> referencesResult = await _symbolsService.FindReferencesOfSymbol( foundSymbol, references, _workspaceService).ConfigureAwait(false); Location[] referenceLocations; if (referencesResult == null) { referenceLocations = s_emptyLocationArray; } else { List <Location> acc = new(); foreach (SymbolReference foundReference in referencesResult) { if (IsReferenceDefinition(foundSymbol, foundReference)) { continue; } DocumentUri uri = DocumentUri.From(foundReference.FilePath); // For any vscode-notebook-cell, we need to ignore the backing file on disk. if (uri.Scheme == "file" && scriptFile.DocumentUri.Scheme == "vscode-notebook-cell" && uri.Path == scriptFile.DocumentUri.Path) { continue; } acc.Add(new Location { Uri = uri, Range = foundReference.ScriptRegion.ToRange() }); } referenceLocations = acc.ToArray(); } return(new CodeLens { Data = codeLens.Data, Range = codeLens.Range, Command = new Command { Name = "editor.action.showReferences", Title = GetReferenceCountHeader(referenceLocations.Length), Arguments = JArray.FromObject(new object[] { scriptFile.DocumentUri, codeLens.Range.Start, referenceLocations }, LspSerializer.Instance.JsonSerializer) } }); }