From bbc17f1c7b8238bacd72aae797d7b1e93ed0a5dc Mon Sep 17 00:00:00 2001 From: Chenjie Shi Date: Tue, 21 Mar 2023 09:26:59 +0800 Subject: [PATCH] Fix Go API view package path render issue and add Go test to APIview CI (#5750) * fix issue of go package path render and add go test to api view ci * fix ci * Update apiview.yml --- src/dotnet/APIView/apiview.yml | 12 ++ src/go/cmd/api_view_test.go | 28 +-- .../{testconst.json => test_const.json} | 120 ++++++----- ...{testfuncdecl.json => test_func_decl.json} | 92 +++++---- ...testinterface.json => test_interface.json} | 104 +++------- .../{teststruct.json => test_struct.json} | 192 +++++++++--------- src/go/cmd/pkg.go | 27 ++- src/go/cmd/testdata/test_const/go.mod | 2 +- src/go/cmd/testdata/test_funcDecl/go.mod | 3 - src/go/cmd/testdata/test_func_decl/go.mod | 3 + .../{test_funcDecl => test_func_decl}/test.go | 0 src/go/cmd/testdata/test_interface/go.mod | 2 +- src/go/cmd/testdata/test_struct/go.mod | 2 +- src/go/cmd/testdata/test_subpackage/go.mod | 2 +- 14 files changed, 280 insertions(+), 309 deletions(-) rename src/go/cmd/output/{testconst.json => test_const.json} (86%) rename src/go/cmd/output/{testfuncdecl.json => test_func_decl.json} (86%) rename src/go/cmd/output/{testinterface.json => test_interface.json} (76%) rename src/go/cmd/output/{teststruct.json => test_struct.json} (83%) delete mode 100644 src/go/cmd/testdata/test_funcDecl/go.mod create mode 100644 src/go/cmd/testdata/test_func_decl/go.mod rename src/go/cmd/testdata/{test_funcDecl => test_func_decl}/test.go (100%) diff --git a/src/dotnet/APIView/apiview.yml b/src/dotnet/APIView/apiview.yml index 58dd12d92a8..9d93e88d506 100644 --- a/src/dotnet/APIView/apiview.yml +++ b/src/dotnet/APIView/apiview.yml @@ -10,6 +10,7 @@ trigger: - .azure-pipelines/apiview.yml - src/dotnet/APIView - src/java/apiview-java-processor + - src/go - src/swift - tools/apiview/parsers/js-api-parser @@ -25,6 +26,7 @@ pr: - .azure-pipelines/apiview.yml - src/dotnet/APIView - src/java/apiview-java-processor + - src/go - src/swift - tools/apiview/parsers/js-api-parser @@ -171,6 +173,16 @@ stages: dotnet --version displayName: 'List .Net run times' + - task: GoTool@0 + inputs: + version: '$(GoVersion)' + displayName: "Use Go $(GoVersion)" + + - script: | + go test ./... -v + workingDirectory: $(GoParserPackagePath) + displayName: 'Test Go parser' + - script: >- dotnet test src/dotnet/APIView/APIViewUnitTests/APIViewUnitTests.csproj --logger trx --collect:"XPlat Code Coverage" diff --git a/src/go/cmd/api_view_test.go b/src/go/cmd/api_view_test.go index 1522164a0ce..cf524260664 100644 --- a/src/go/cmd/api_view_test.go +++ b/src/go/cmd/api_view_test.go @@ -18,11 +18,11 @@ func TestMain(m *testing.M) { } func TestFuncDecl(t *testing.T) { - err := CreateAPIView(filepath.Clean("testdata/test_funcDecl"), "output") + err := CreateAPIView(filepath.Clean("testdata/test_func_decl"), "output") if err != nil { t.Fatal(err) } - file, err := os.ReadFile("./output/testfuncdecl.json") + file, err := os.ReadFile("./output/test_func_decl.json") if err != nil { t.Fatal(err) } @@ -31,10 +31,10 @@ func TestFuncDecl(t *testing.T) { if err != nil { t.Fatal(err) } - if len(p.Tokens) != 41 { + if len(p.Tokens) != 42 { t.Fatal("unexpected token length, signals a change in the output") } - if p.Name != "testfuncdecl" { + if p.Name != "test_func_decl" { t.Fatal("unexpected package name") } if len(p.Navigation) != 1 { @@ -50,7 +50,7 @@ func TestInterface(t *testing.T) { if err != nil { t.Fatal(err) } - file, err := os.ReadFile("./output/testinterface.json") + file, err := os.ReadFile("./output/test_interface.json") if err != nil { t.Fatal(err) } @@ -59,10 +59,10 @@ func TestInterface(t *testing.T) { if err != nil { t.Fatal(err) } - if len(p.Tokens) != 55 { + if len(p.Tokens) != 46 { t.Fatal("unexpected token length, signals a change in the output") } - if p.Name != "testinterface" { + if p.Name != "test_interface" { t.Fatal("unexpected package name") } if len(p.Navigation) != 1 { @@ -78,7 +78,7 @@ func TestStruct(t *testing.T) { if err != nil { t.Fatal(err) } - file, err := os.ReadFile("./output/teststruct.json") + file, err := os.ReadFile("./output/test_struct.json") if err != nil { t.Fatal(err) } @@ -87,16 +87,16 @@ func TestStruct(t *testing.T) { if err != nil { t.Fatal(err) } - if len(p.Tokens) != 69 { + if len(p.Tokens) != 68 { t.Fatal("unexpected token length, signals a change in the output") } - if p.Name != "teststruct" { + if p.Name != "test_struct" { t.Fatal("unexpected package name") } if len(p.Navigation) != 1 { t.Fatal("nagivation slice length should only be one for one package") } - if len(p.Navigation[0].ChildItems) != 2 { + if len(p.Navigation[0].ChildItems) != 1 { t.Fatal("nagivation slice length should include link for ctor and struct") } } @@ -106,7 +106,7 @@ func TestConst(t *testing.T) { if err != nil { t.Fatal(err) } - file, err := os.ReadFile("./output/testconst.json") + file, err := os.ReadFile("./output/test_const.json") if err != nil { t.Fatal(err) } @@ -118,13 +118,13 @@ func TestConst(t *testing.T) { if len(p.Tokens) != 76 { t.Fatal("unexpected token length, signals a change in the output") } - if p.Name != "testconst" { + if p.Name != "test_const" { t.Fatal("unexpected package name") } if len(p.Navigation) != 1 { t.Fatal("nagivation slice length should only be one for one package") } - if len(p.Navigation[0].ChildItems) != 3 { + if len(p.Navigation[0].ChildItems) != 4 { t.Fatal("unexpected child navigation items length") } } diff --git a/src/go/cmd/output/testconst.json b/src/go/cmd/output/test_const.json similarity index 86% rename from src/go/cmd/output/testconst.json rename to src/go/cmd/output/test_const.json index 9ad1917f6dd..82a560e1176 100644 --- a/src/go/cmd/output/testconst.json +++ b/src/go/cmd/output/test_const.json @@ -1,5 +1,6 @@ { - "Name": "testconst", + "Language": "Go", + "Name": "test_const", "Tokens": [ { "DefinitionId": null, @@ -14,9 +15,9 @@ "Kind": 2 }, { - "DefinitionId": "testconst", + "DefinitionId": "test_const", "NavigateToId": null, - "Value": "testconst", + "Value": "test_const", "Kind": 4 }, { @@ -28,20 +29,26 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": " ", - "Kind": 2 + "Value": "", + "Kind": 1 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "", - "Kind": 1 + "Value": "type", + "Kind": 6 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "", - "Kind": 1 + "Value": " ", + "Kind": 2 + }, + { + "DefinitionId": "test_const.SomeChoice", + "NavigateToId": null, + "Value": "SomeChoice", + "Kind": 4 }, { "DefinitionId": null, @@ -49,6 +56,18 @@ "Value": " ", "Kind": 2 }, + { + "DefinitionId": null, + "NavigateToId": null, + "Value": "int64", + "Kind": 4 + }, + { + "DefinitionId": null, + "NavigateToId": null, + "Value": "", + "Kind": 1 + }, { "DefinitionId": null, "NavigateToId": null, @@ -56,7 +75,7 @@ "Kind": 1 }, { - "DefinitionId": "SomeChoice", + "DefinitionId": null, "NavigateToId": null, "Value": "const", "Kind": 6 @@ -86,7 +105,7 @@ "Kind": 2 }, { - "DefinitionId": "Choice1", + "DefinitionId": "test_const.Choice1", "NavigateToId": null, "Value": "Choice1", "Kind": 4 @@ -99,9 +118,9 @@ }, { "DefinitionId": null, - "NavigateToId": null, + "NavigateToId": "test_const.SomeChoice", "Value": "SomeChoice", - "Kind": 7 + "Kind": 4 }, { "DefinitionId": null, @@ -140,7 +159,7 @@ "Kind": 2 }, { - "DefinitionId": "Choice2", + "DefinitionId": "test_const.Choice2", "NavigateToId": null, "Value": "Choice2", "Kind": 4 @@ -153,9 +172,9 @@ }, { "DefinitionId": null, - "NavigateToId": null, + "NavigateToId": "test_const.SomeChoice", "Value": "SomeChoice", - "Kind": 7 + "Kind": 4 }, { "DefinitionId": null, @@ -208,18 +227,6 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": " ", - "Kind": 2 - }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": "", - "Kind": 1 - }, - { - "DefinitionId": "Untyped const", - "NavigateToId": null, "Value": "const", "Kind": 6 }, @@ -248,7 +255,7 @@ "Kind": 2 }, { - "DefinitionId": "Agent", + "DefinitionId": "test_const.Agent", "NavigateToId": null, "Value": "Agent", "Kind": 4 @@ -296,7 +303,7 @@ "Kind": 2 }, { - "DefinitionId": "Version", + "DefinitionId": "test_const.Version", "NavigateToId": null, "Value": "Version", "Kind": 4 @@ -358,18 +365,6 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": " ", - "Kind": 2 - }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": "", - "Kind": 1 - }, - { - "DefinitionId": "string", - "NavigateToId": null, "Value": "const", "Kind": 6 }, @@ -398,7 +393,7 @@ "Kind": 2 }, { - "DefinitionId": "SomeConst", + "DefinitionId": "test_const.SomeConst", "NavigateToId": null, "Value": "SomeConst", "Kind": 4 @@ -413,7 +408,7 @@ "DefinitionId": null, "NavigateToId": null, "Value": "string", - "Kind": 7 + "Kind": 4 }, { "DefinitionId": null, @@ -451,6 +446,12 @@ "Value": ")", "Kind": 3 }, + { + "DefinitionId": null, + "NavigateToId": null, + "Value": "", + "Kind": 1 + }, { "DefinitionId": null, "NavigateToId": null, @@ -460,35 +461,46 @@ ], "Navigation": [ { - "Text": "testconst", - "NavigationId": null, + "Text": "test_const", + "NavigationId": "test_const", "ChildItems": [ { - "Text": "SomeChoice", - "NavigationId": "SomeChoice", + "Text": "Agent", + "NavigationId": "test_const.Agent", "ChildItems": [], "Tags": { "TypeKind": "enum" } }, { - "Text": "string", - "NavigationId": "string", + "Text": "SomeChoice", + "NavigationId": "test_const.SomeChoice", + "ChildItems": [], + "Tags": { + "TypeKind": "struct" + } + }, + { + "Text": "SomeConst", + "NavigationId": "test_const.SomeConst", "ChildItems": [], "Tags": { "TypeKind": "enum" } }, { - "Text": "Untyped const", - "NavigationId": "Untyped const", + "Text": "Version", + "NavigationId": "test_const.Version", "ChildItems": [], "Tags": { "TypeKind": "enum" } } ], - "Tags": null + "Tags": { + "TypeKind": "namespace" + } } - ] + ], + "PackageName": "test_const" } \ No newline at end of file diff --git a/src/go/cmd/output/testfuncdecl.json b/src/go/cmd/output/test_func_decl.json similarity index 86% rename from src/go/cmd/output/testfuncdecl.json rename to src/go/cmd/output/test_func_decl.json index a07a8244690..7a93f6d8e42 100644 --- a/src/go/cmd/output/testfuncdecl.json +++ b/src/go/cmd/output/test_func_decl.json @@ -1,5 +1,6 @@ { - "Name": "testfuncdecl", + "Language": "Go", + "Name": "test_func_decl", "Tokens": [ { "DefinitionId": null, @@ -14,9 +15,9 @@ "Kind": 2 }, { - "DefinitionId": "testfuncdecl", + "DefinitionId": "test_func_decl", "NavigateToId": null, - "Value": "testfuncdecl", + "Value": "test_func_decl", "Kind": 4 }, { @@ -25,12 +26,6 @@ "Value": "", "Kind": 1 }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": " ", - "Kind": 2 - }, { "DefinitionId": null, "NavigateToId": null, @@ -40,8 +35,8 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "", - "Kind": 1 + "Value": "func", + "Kind": 6 }, { "DefinitionId": null, @@ -49,17 +44,23 @@ "Value": " ", "Kind": 2 }, + { + "DefinitionId": "test_func_decl-DoSomething", + "NavigateToId": null, + "Value": "DoSomething", + "Kind": 4 + }, { "DefinitionId": null, "NavigateToId": null, - "Value": "", - "Kind": 1 + "Value": "(", + "Kind": 3 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "func", - "Kind": 6 + "Value": "s", + "Kind": 7 }, { "DefinitionId": null, @@ -68,22 +69,28 @@ "Kind": 2 }, { - "DefinitionId": "DoSomething", + "DefinitionId": null, "NavigateToId": null, - "Value": "DoSomething", + "Value": "string", "Kind": 4 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "(", + "Value": ",", "Kind": 3 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "s", - "Kind": 4 + "Value": " ", + "Kind": 2 + }, + { + "DefinitionId": null, + "NavigateToId": null, + "Value": "i", + "Kind": 7 }, { "DefinitionId": null, @@ -94,8 +101,8 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "string", - "Kind": 7 + "Value": "int", + "Kind": 4 }, { "DefinitionId": null, @@ -112,8 +119,8 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "i", - "Kind": 4 + "Value": "b", + "Kind": 7 }, { "DefinitionId": null, @@ -124,8 +131,8 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "int", - "Kind": 7 + "Value": "bool", + "Kind": 4 }, { "DefinitionId": null, @@ -142,8 +149,8 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "b", - "Kind": 4 + "Value": "f1", + "Kind": 7 }, { "DefinitionId": null, @@ -154,8 +161,8 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "bool", - "Kind": 7 + "Value": "float32", + "Kind": 4 }, { "DefinitionId": null, @@ -172,8 +179,8 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "f1", - "Kind": 4 + "Value": "f2", + "Kind": 7 }, { "DefinitionId": null, @@ -185,7 +192,7 @@ "DefinitionId": null, "NavigateToId": null, "Value": "float32", - "Kind": 7 + "Kind": 4 }, { "DefinitionId": null, @@ -209,7 +216,7 @@ "DefinitionId": null, "NavigateToId": null, "Value": "string", - "Kind": 7 + "Kind": 4 }, { "DefinitionId": null, @@ -227,7 +234,7 @@ "DefinitionId": null, "NavigateToId": null, "Value": "error", - "Kind": 7 + "Kind": 4 }, { "DefinitionId": null, @@ -250,19 +257,22 @@ ], "Navigation": [ { - "Text": "testfuncdecl", - "NavigationId": null, + "Text": "test_func_decl", + "NavigationId": "test_func_decl", "ChildItems": [ { "Text": "DoSomething", - "NavigationId": "DoSomething", + "NavigationId": "test_func_decl-DoSomething", "ChildItems": [], "Tags": { - "TypeKind": "unknown" + "TypeKind": "delegate" } } ], - "Tags": null + "Tags": { + "TypeKind": "namespace" + } } - ] + ], + "PackageName": "test_func_decl" } \ No newline at end of file diff --git a/src/go/cmd/output/testinterface.json b/src/go/cmd/output/test_interface.json similarity index 76% rename from src/go/cmd/output/testinterface.json rename to src/go/cmd/output/test_interface.json index 9150d39efcf..8e9cf754423 100644 --- a/src/go/cmd/output/testinterface.json +++ b/src/go/cmd/output/test_interface.json @@ -1,5 +1,6 @@ { - "Name": "testinterface", + "Language": "Go", + "Name": "test_interface", "Tokens": [ { "DefinitionId": null, @@ -14,9 +15,9 @@ "Kind": 2 }, { - "DefinitionId": "testinterface", + "DefinitionId": "test_interface", "NavigateToId": null, - "Value": "testinterface", + "Value": "test_interface", "Kind": 4 }, { @@ -25,12 +26,6 @@ "Value": "", "Kind": 1 }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": " ", - "Kind": 2 - }, { "DefinitionId": null, "NavigateToId": null, @@ -50,8 +45,8 @@ "Kind": 2 }, { - "DefinitionId": "EmbeddedInt", - "NavigateToId": "EmbeddedInt", + "DefinitionId": "test_interface.EmbeddedInt", + "NavigateToId": null, "Value": "EmbeddedInt", "Kind": 4 }, @@ -92,7 +87,7 @@ "Kind": 2 }, { - "DefinitionId": "Bar", + "DefinitionId": "test_interface-EmbeddedInt-Bar", "NavigateToId": null, "Value": "Bar", "Kind": 4 @@ -107,7 +102,7 @@ "DefinitionId": null, "NavigateToId": null, "Value": "b", - "Kind": 9 + "Kind": 7 }, { "DefinitionId": null, @@ -119,7 +114,7 @@ "DefinitionId": null, "NavigateToId": null, "Value": "string", - "Kind": 9 + "Kind": 4 }, { "DefinitionId": null, @@ -127,18 +122,6 @@ "Value": ")", "Kind": 3 }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": " ", - "Kind": 2 - }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": "", - "Kind": 1 - }, { "DefinitionId": null, "NavigateToId": null, @@ -157,12 +140,6 @@ "Value": "", "Kind": 1 }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": " ", - "Kind": 2 - }, { "DefinitionId": null, "NavigateToId": null, @@ -182,8 +159,8 @@ "Kind": 2 }, { - "DefinitionId": "SomeInterface", - "NavigateToId": "SomeInterface", + "DefinitionId": "test_interface.SomeInterface", + "NavigateToId": null, "Value": "SomeInterface", "Kind": 4 }, @@ -224,25 +201,7 @@ "Kind": 2 }, { - "DefinitionId": "EmbeddedInt-SomeInterface", - "NavigateToId": null, - "Value": "EmbeddedInt", - "Kind": 4 - }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": "", - "Kind": 1 - }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": "\t", - "Kind": 2 - }, - { - "DefinitionId": "Foo", + "DefinitionId": "test_interface-SomeInterface-Foo", "NavigateToId": null, "Value": "Foo", "Kind": 4 @@ -257,7 +216,7 @@ "DefinitionId": null, "NavigateToId": null, "Value": "bar", - "Kind": 9 + "Kind": 7 }, { "DefinitionId": null, @@ -269,7 +228,7 @@ "DefinitionId": null, "NavigateToId": null, "Value": "int64", - "Kind": 9 + "Kind": 4 }, { "DefinitionId": null, @@ -286,20 +245,14 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "*bool", - "Kind": 9 - }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": "", - "Kind": 1 + "Value": "*", + "Kind": 3 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "", - "Kind": 1 + "Value": "bool", + "Kind": 4 }, { "DefinitionId": null, @@ -319,12 +272,6 @@ "Value": "", "Kind": 1 }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": " ", - "Kind": 2 - }, { "DefinitionId": null, "NavigateToId": null, @@ -334,12 +281,12 @@ ], "Navigation": [ { - "Text": "testinterface", - "NavigationId": null, + "Text": "test_interface", + "NavigationId": "test_interface", "ChildItems": [ { "Text": "EmbeddedInt", - "NavigationId": "EmbeddedInt", + "NavigationId": "test_interface.EmbeddedInt", "ChildItems": [], "Tags": { "TypeKind": "interface" @@ -347,14 +294,17 @@ }, { "Text": "SomeInterface", - "NavigationId": "SomeInterface", + "NavigationId": "test_interface.SomeInterface", "ChildItems": [], "Tags": { "TypeKind": "interface" } } ], - "Tags": null + "Tags": { + "TypeKind": "namespace" + } } - ] + ], + "PackageName": "test_interface" } \ No newline at end of file diff --git a/src/go/cmd/output/teststruct.json b/src/go/cmd/output/test_struct.json similarity index 83% rename from src/go/cmd/output/teststruct.json rename to src/go/cmd/output/test_struct.json index 3a8ae434502..38fc27f0cc5 100644 --- a/src/go/cmd/output/teststruct.json +++ b/src/go/cmd/output/test_struct.json @@ -1,5 +1,6 @@ { - "Name": "teststruct", + "Language": "Go", + "Name": "test_struct", "Tokens": [ { "DefinitionId": null, @@ -14,9 +15,9 @@ "Kind": 2 }, { - "DefinitionId": "teststruct", + "DefinitionId": "test_struct", "NavigateToId": null, - "Value": "teststruct", + "Value": "test_struct", "Kind": 4 }, { @@ -25,30 +26,6 @@ "Value": "", "Kind": 1 }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": " ", - "Kind": 2 - }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": "", - "Kind": 1 - }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": "", - "Kind": 1 - }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": " ", - "Kind": 2 - }, { "DefinitionId": null, "NavigateToId": null, @@ -68,8 +45,8 @@ "Kind": 2 }, { - "DefinitionId": "SomeStruct", - "NavigateToId": "SomeStruct", + "DefinitionId": "test_struct.SomeStruct", + "NavigateToId": null, "Value": "SomeStruct", "Kind": 4 }, @@ -110,7 +87,7 @@ "Kind": 2 }, { - "DefinitionId": "Foo-SomeStruct", + "DefinitionId": "Foo-test_struct.SomeStruct", "NavigateToId": null, "Value": "Foo", "Kind": 4 @@ -124,8 +101,14 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "*bool", - "Kind": 7 + "Value": "*", + "Kind": 3 + }, + { + "DefinitionId": null, + "NavigateToId": null, + "Value": "bool", + "Kind": 4 }, { "DefinitionId": null, @@ -140,7 +123,7 @@ "Kind": 2 }, { - "DefinitionId": "Resp-SomeStruct", + "DefinitionId": "Resp-test_struct.SomeStruct", "NavigateToId": null, "Value": "Resp", "Kind": 4 @@ -154,8 +137,14 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "*http.Response", - "Kind": 7 + "Value": "*", + "Kind": 3 + }, + { + "DefinitionId": null, + "NavigateToId": null, + "Value": "http.Response", + "Kind": 4 }, { "DefinitionId": null, @@ -175,6 +164,12 @@ "Value": "", "Kind": 1 }, + { + "DefinitionId": null, + "NavigateToId": null, + "Value": "", + "Kind": 1 + }, { "DefinitionId": null, "NavigateToId": null, @@ -188,7 +183,7 @@ "Kind": 2 }, { - "DefinitionId": "NewSomeStruct", + "DefinitionId": "test_struct-NewSomeStruct", "NavigateToId": null, "Value": "NewSomeStruct", "Kind": 4 @@ -214,8 +209,14 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "*SomeStruct", - "Kind": 7 + "Value": "*", + "Kind": 3 + }, + { + "DefinitionId": null, + "NavigateToId": "test_struct.SomeStruct", + "Value": "SomeStruct", + "Kind": 4 }, { "DefinitionId": null, @@ -241,6 +242,12 @@ "Value": " ", "Kind": 2 }, + { + "DefinitionId": "test_struct-NewStruct", + "NavigateToId": null, + "Value": "NewStruct", + "Kind": 4 + }, { "DefinitionId": null, "NavigateToId": null, @@ -250,8 +257,8 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "s", - "Kind": 7 + "Value": ")", + "Kind": 3 }, { "DefinitionId": null, @@ -263,43 +270,31 @@ "DefinitionId": null, "NavigateToId": null, "Value": "*", - "Kind": 7 + "Kind": 3 }, { "DefinitionId": null, - "NavigateToId": null, + "NavigateToId": "test_struct.SomeStruct", "Value": "SomeStruct", - "Kind": 7 - }, - { - "DefinitionId": null, - "NavigateToId": null, - "Value": ")", - "Kind": 3 + "Kind": 4 }, { "DefinitionId": null, "NavigateToId": null, - "Value": " ", - "Kind": 2 - }, - { - "DefinitionId": "Update-SomeStruct", - "NavigateToId": null, - "Value": "Update", - "Kind": 4 + "Value": "", + "Kind": 1 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "(", - "Kind": 3 + "Value": "", + "Kind": 1 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "resp", - "Kind": 4 + "Value": "func", + "Kind": 6 }, { "DefinitionId": null, @@ -310,14 +305,14 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "*http.Response", - "Kind": 9 + "Value": "(", + "Kind": 3 }, { "DefinitionId": null, "NavigateToId": null, - "Value": ")", - "Kind": 3 + "Value": "s", + "Kind": 7 }, { "DefinitionId": null, @@ -328,44 +323,44 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "error", - "Kind": 7 + "Value": "*", + "Kind": 3 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "", - "Kind": 1 + "Value": "SomeStruct", + "Kind": 4 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "", - "Kind": 1 + "Value": ")", + "Kind": 3 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "", - "Kind": 1 + "Value": " ", + "Kind": 2 }, { - "DefinitionId": null, + "DefinitionId": "test_struct-(s *SomeStruct) Update", "NavigateToId": null, - "Value": " ", - "Kind": 2 + "Value": "Update", + "Kind": 4 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "", - "Kind": 1 + "Value": "(", + "Kind": 3 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "func", - "Kind": 6 + "Value": "resp", + "Kind": 7 }, { "DefinitionId": null, @@ -374,16 +369,16 @@ "Kind": 2 }, { - "DefinitionId": "NewStruct", + "DefinitionId": null, "NavigateToId": null, - "Value": "NewStruct", - "Kind": 4 + "Value": "*", + "Kind": 3 }, { "DefinitionId": null, "NavigateToId": null, - "Value": "(", - "Kind": 3 + "Value": "http.Response", + "Kind": 4 }, { "DefinitionId": null, @@ -400,8 +395,8 @@ { "DefinitionId": null, "NavigateToId": null, - "Value": "*SomeStruct", - "Kind": 7 + "Value": "error", + "Kind": 4 }, { "DefinitionId": null, @@ -418,27 +413,22 @@ ], "Navigation": [ { - "Text": "teststruct", - "NavigationId": null, + "Text": "test_struct", + "NavigationId": "test_struct", "ChildItems": [ { "Text": "SomeStruct", - "NavigationId": "SomeStruct", - "ChildItems": [], - "Tags": { - "TypeKind": "struct" - } - }, - { - "Text": "NewStruct", - "NavigationId": "NewStruct", + "NavigationId": "test_struct.SomeStruct", "ChildItems": [], "Tags": { - "TypeKind": "unknown" + "TypeKind": "class" } } ], - "Tags": null + "Tags": { + "TypeKind": "namespace" + } } - ] + ], + "PackageName": "test_struct" } \ No newline at end of file diff --git a/src/go/cmd/pkg.go b/src/go/cmd/pkg.go index 08516587a10..fbce2298453 100644 --- a/src/go/cmd/pkg.go +++ b/src/go/cmd/pkg.go @@ -58,18 +58,15 @@ func NewPkg(dir, modulePath string) (*Pkg, error) { types: map[string]typeDef{}, } modulePathWithoutVersion := strings.TrimSuffix(versionReg.ReplaceAllString(modulePath, "/"), "/") - if _, after, found := strings.Cut(modulePathWithoutVersion, "azure-sdk-for-go/sdk/"); found { - if _, after, found := strings.Cut(dir, filepath.Clean(after)); found { - pk.relName = path.Base(modulePathWithoutVersion) - if after != "" { - pk.relName += after - } - pk.relName = strings.ReplaceAll(pk.relName, "\\", "/") - } else { - return nil, errors.New(dir + " isn't part of module " + modulePath) + moduleName := filepath.Base(modulePathWithoutVersion) + if _, after, found := strings.Cut(dir, moduleName); found { + pk.relName = moduleName + if after != "" { + pk.relName += after } + pk.relName = strings.ReplaceAll(pk.relName, "\\", "/") } else { - return nil, errors.New(dir + " isn't part of module " + modulePath) + return nil, errors.New(dir + " isn't part of module " + moduleName) } pk.files = map[string][]byte{} pk.fs = token.NewFileSet() @@ -175,12 +172,12 @@ func (p *Pkg) indexFile(f *ast.File) { if _, _, found := strings.Cut(impPath, p.modulePath); found && !strings.Contains(impPath, "internal") { expr := p.getText(t.Pos(), t.End()) p.c.addSimpleType(*p, x.Name.Name, p.Name(), expr, imports) - } else { - // This is a re-exported type e.g. "type TokenCredential = shared.TokenCredential". - // Track it as an alias so we can later hoist its definition into this package. - qn := impPath + "." + t.Sel.Name - p.typeAliases[x.Name.Name] = qn } + + // This is a re-exported type e.g. "type TokenCredential = shared.TokenCredential". + // Track it as an alias so we can later hoist its definition into this package. + qn := impPath + "." + t.Sel.Name + p.typeAliases[x.Name.Name] = qn } else { // Non-SDK underlying type e.g. "type EDMDateTime time.Time". Handle it like a simple type // because we don't want to hoist its definition into this package. diff --git a/src/go/cmd/testdata/test_const/go.mod b/src/go/cmd/testdata/test_const/go.mod index b12e6f28575..6a9cae896eb 100644 --- a/src/go/cmd/testdata/test_const/go.mod +++ b/src/go/cmd/testdata/test_const/go.mod @@ -1,3 +1,3 @@ -module testsconst +module test_const go 1.13 diff --git a/src/go/cmd/testdata/test_funcDecl/go.mod b/src/go/cmd/testdata/test_funcDecl/go.mod deleted file mode 100644 index 1ce0ca56ade..00000000000 --- a/src/go/cmd/testdata/test_funcDecl/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module testfuncdecl - -go 1.13 diff --git a/src/go/cmd/testdata/test_func_decl/go.mod b/src/go/cmd/testdata/test_func_decl/go.mod new file mode 100644 index 00000000000..ef47fa4447f --- /dev/null +++ b/src/go/cmd/testdata/test_func_decl/go.mod @@ -0,0 +1,3 @@ +module test_func_decl + +go 1.13 diff --git a/src/go/cmd/testdata/test_funcDecl/test.go b/src/go/cmd/testdata/test_func_decl/test.go similarity index 100% rename from src/go/cmd/testdata/test_funcDecl/test.go rename to src/go/cmd/testdata/test_func_decl/test.go diff --git a/src/go/cmd/testdata/test_interface/go.mod b/src/go/cmd/testdata/test_interface/go.mod index ff0549784a7..6c8a5f86ba9 100644 --- a/src/go/cmd/testdata/test_interface/go.mod +++ b/src/go/cmd/testdata/test_interface/go.mod @@ -1,3 +1,3 @@ -module testinterface +module test_interface go 1.13 diff --git a/src/go/cmd/testdata/test_struct/go.mod b/src/go/cmd/testdata/test_struct/go.mod index c6f3ea548a1..15e1d33fdd1 100644 --- a/src/go/cmd/testdata/test_struct/go.mod +++ b/src/go/cmd/testdata/test_struct/go.mod @@ -1,3 +1,3 @@ -module teststruct +module test_struct go 1.13 diff --git a/src/go/cmd/testdata/test_subpackage/go.mod b/src/go/cmd/testdata/test_subpackage/go.mod index e9d175ee5b7..d0c61535139 100644 --- a/src/go/cmd/testdata/test_subpackage/go.mod +++ b/src/go/cmd/testdata/test_subpackage/go.mod @@ -1,3 +1,3 @@ -module testsubpackage +module test_subpackage go 1.18