From bde7a4686700f9cfd43ed552aa0c8f27a2c018dc Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Sun, 9 Apr 2017 09:42:55 -0700 Subject: [PATCH 1/7] Use stdin to read file contents --- main.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 4ef56c9..7313715 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,8 @@ import ( "go/parser" "go/token" "os" + + "golang.org/x/tools/go/buildutil" ) type Declaration struct { @@ -24,7 +26,7 @@ type Declaration struct { var ( file = flag.String("f", "", "the path to the file to outline") importsOnly = flag.Bool("imports-only", false, "parse imports only") - src = flag.String("src", "", "source code of the file to outline") + modified = flag.Bool("modified", false, "read an archive of the modified file from standard input") ) func main() { @@ -38,8 +40,16 @@ func main() { var fileAst *ast.File var err error - if len(*src) > 0 { - fileAst, err = parser.ParseFile(fset, *file, *src, parserMode) + if *modified == true { + archive, err := buildutil.ParseOverlayArchive(os.Stdin) + if err != nil { + reportError(fmt.Errorf("failed to parse -modified archive: %v", err)) + } + fc, ok := archive[*file] + if !ok { + reportError(fmt.Errorf("couldn't find %s in archive", *file)) + } + fileAst, err = parser.ParseFile(fset, *file, fc, parserMode) } else { fileAst, err = parser.ParseFile(fset, *file, nil, parserMode) } From 3bda790435a5ed938d45b99c4313e079d3db368e Mon Sep 17 00:00:00 2001 From: Ramya Rao Date: Sun, 9 Apr 2017 09:46:37 -0700 Subject: [PATCH 2/7] Updating for -modified flag --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 6b76df9..dae608b 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,14 @@ To parse and return only imports > go-outline -f file.go -imports-only ``` +To parse unsaved file contents, use the `-modified` flag along with the `-f` flag and write an archive to stdin. +File in the archive will be preferred over the one on disk. + +The archive entry consists of: + - the file name, followed by a newline + - the (decimal) file size, followed by a newline + - the contents of the file + ### Schema ```go type Declaration struct { From 9e9d089bb61a5ce4f8e0c8d8dc5b4e41b0e02a48 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Fri, 4 Aug 2017 02:00:19 +0300 Subject: [PATCH 3/7] Fix installing instructions (#2) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dae608b..43e86d0 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Go source file. ## Installing ```bash -go get -u github.com/lukehoban/go-outline +go get -u github.com/ramya-rao-a/go-outline ``` ## Using From d26487fd6f3dc19ff07dac0e8b3cf5872ae13bde Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 22 Nov 2018 03:50:44 +0100 Subject: [PATCH 4/7] Fix license detection on GitHub (#6) The first line prevented GitHub from automatically recognizing the license. --- LICENSE | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index f166619..5ae193c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,3 @@ -go-outline - The MIT License (MIT) Copyright (c) Microsoft Corporation @@ -20,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. From 7182a932836a71948db4a81991a494751eccfe77 Mon Sep 17 00:00:00 2001 From: Nexus Web Development Date: Wed, 21 Nov 2018 21:51:42 -0500 Subject: [PATCH 5/7] Fixes no formatting directive in Errorf call (#4) --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 7313715..1f144d9 100644 --- a/main.go +++ b/main.go @@ -113,7 +113,7 @@ func main() { } } default: - reportError(fmt.Errorf("Unknown declaration @", decl.Pos())) + reportError(fmt.Errorf("Unknown declaration @ %v", decl.Pos())) } } From 2a048b4510eb36ad1bb2913a1f5c95605d819f32 Mon Sep 17 00:00:00 2001 From: Henry Kwan Date: Fri, 17 Jan 2020 10:16:46 +0800 Subject: [PATCH 6/7] To differentiate var vs const from *ValueSpec (#10) --- main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 1f144d9..7374b62 100644 --- a/main.go +++ b/main.go @@ -99,9 +99,13 @@ func main() { }) case *ast.ValueSpec: for _, id := range spec.Names { + varOrConst := "variable" + if decl.Tok == token.CONST { + varOrConst = "constant" + } declarations = append(declarations, Declaration{ id.Name, - "variable", + varOrConst, "", id.Pos(), id.End(), From 9736a4bde949f321d201e5eaa5ae2bcde011bf00 Mon Sep 17 00:00:00 2001 From: Hunter Breathat <29546913+Nexushunter@users.noreply.github.com> Date: Tue, 8 Jun 2021 12:15:38 -0400 Subject: [PATCH 7/7] Add go mod to allow manual install (Should fix vscode install issue) (#14) --- go.mod | 5 +++++ go.sum | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7038c5d --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/ramya-rao-a/go-outline + +go 1.16 + +require golang.org/x/tools v0.1.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..9ba29a2 --- /dev/null +++ b/go.sum @@ -0,0 +1,27 @@ +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=