Skip to content

Commit 898c6d0

Browse files
authored
Merge pull request #135 from digma-ai/workaround/go-links
workaround to make go links work
2 parents 810dd2e + 89a7a64 commit 898c6d0

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

src/services/EditorHelper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface EditorInfo {
1919
export interface InstrumentationInfo {
2020
instrumentationName?: string;
2121
spanName?: string;
22+
fullName?: string
2223
}
2324

2425
export class EditorHelper {

src/services/documentInfoProvider.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Token, TokenType } from './languages/tokens';
77
import { Dictionary, Future } from './utils';
88
import { EndpointInfo, SpanInfo, SymbolInfo, CodeObjectInfo } from './languages/extractors';
99
import { InstrumentationInfo } from './EditorHelper';
10+
import { SymbolInformation } from 'vscode';
1011

1112
export class DocumentInfoProvider implements vscode.Disposable
1213
{
@@ -47,11 +48,31 @@ export class DocumentInfoProvider implements vscode.Disposable
4748

4849
public async searchForSpan(instrumentationInfo: InstrumentationInfo): Promise<SpanInfo|undefined>{
4950
const codeFileHint = instrumentationInfo.instrumentationName;
50-
if (codeFileHint){
51+
52+
if (codeFileHint ){
53+
54+
if (vscode.window.activeTextEditor?.document.fileName.toLocaleLowerCase().endsWith(".go")){
55+
56+
//TODO: change to use document info we alrady scanned
57+
let regex = /(\(\*?.*\).*)/;
58+
//workaround for GO
59+
let match = instrumentationInfo.fullName?.match(regex)?.firstOrDefault();
60+
if (match){
61+
match =match?.replace("(*","").replace(")","");
62+
let codeLocations:SymbolInformation[] = await vscode.commands.executeCommand("vscode.executeWorkspaceSymbolProvider", match);
63+
if (codeLocations){
64+
codeLocations=codeLocations.filter(x=>x.kind===vscode.SymbolKind.Method && x.name===match);
65+
if (codeLocations.length===1){
66+
return new SpanInfo(instrumentationInfo.fullName!,instrumentationInfo.spanName!, codeLocations[0].location.range, codeLocations[0].location.uri);
67+
}
68+
}
69+
}
70+
}
71+
5172

5273
if (codeFileHint==='__main__'){
5374

54-
let doc = vscode.window.activeTextEditor?.document
75+
let doc = vscode.window.activeTextEditor?.document;
5576
if (doc){
5677
const docInfo = await this.getDocumentInfo(doc);
5778
if (docInfo){

src/services/languages/go/methodExtractor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class GoMethodExtractor implements IMethodExtractor{
6262
// "AuthController.Error" => "AuthController.Error"
6363
// "(*AuthController).Error" => "(*AuthController).Error"
6464
// "(AuthController).Error" => "AuthController.Error"
65-
let name = s.name.replace(/\(([^*]+)\)\.(.+)/, "$1.$2")
65+
let name = s.name.replace(/\(([^*]+)\)\.(.+)/, "$1.$2");
6666
return {
6767
id: packageDefinitionName === "main" ? packagePath + '$_$' + `main.${name}` : packagePath + '$_$' + name,
6868
name: name,

src/views/codeAnalytics/InsightListView/EndpointInsight.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class SlowestSpansListViewItemsCreator implements IInsightListViewItemsCr
179179
var spansLocations = spans.map(span=>
180180
{ return {
181181
slowspaninfo : span,
182-
spanSearchResult : this._documentInfoProvider.searchForSpan({ instrumentationName : span.spanInfo.instrumentationLibrary.split(".").join( " "), spanName :span.spanInfo.name })
182+
spanSearchResult : this._documentInfoProvider.searchForSpan({ instrumentationName : span.spanInfo.instrumentationLibrary.split(".").join( " "), spanName :span.spanInfo.name, fullName:span.spanInfo.name })
183183
};
184184
});
185185

0 commit comments

Comments
 (0)