Git Product home page Git Product logo

godoctor's Introduction

The Go Doctor

build GoDoc Project Status

A golang refactoring tool

http://gorefactor.org

                                 .,;;::;;;;::;,.                    
                           .'.......         ......'.               
                  .'.'. .,,'......        .''...''. .,;:'.''.       
                ':;,..::..,'.   ..',     ,.       .,.  ';...,c.     
              ',ccdXXx. .; .       .:   c.,c;       l    dXXklc,,.  
            .:;cc .:O.  ;,0XO,      ;.  l;X0d;      c.   .kl'::,;:' 
           .l,, ''.:'   ,:kOc'      ;.  ,:lo;.     .:     'l'.  .;;'
           ;,;    'c     ;,       .;''clc:;'.    .,.       :     ;.;
           ;,;    :,      ........:',kKXKx';:.....         :.    ;.;
           .c,'   l'              :    .    :.             ;.   .;',
            ,;;.  l.              .',.,:.',.'              ;;   ;,: 
             .;;, l.                ; .: .;                ,: ';;,  
              .';:c:                ..',.'.                ;l,:'.   
                 .,c:,.                                 .';c;'      
                   c',c:,'                           .',c,,cc       
         .'....'.  ;   .';c;...                  ..,c:'..  .l       
        ,' .''. ,. :       ''::''.           .'';c,'.      .o       
        ;  :  : .l.c.         ..';ll.......:l:'...         .x'',,   
        .:..''..c,.l.             ;;.     .,:               d;.cl.  
          ....:cc..c                .''.''.                 l,..    
              .c;' :                  lc;                   c'      
               .:;l:                  l:,                   c,      
                 ;::.                 l:,                   :,      
                  :c;'                l:'                   :,      
                  ,o;;,.             ;;;                    c'      
                  '; ';:,'.        ';::                     l.      
                   :   ..;c:,'.',;c;'.                     .l       
                   :       .......                         ;.       
                   ':                                     ;,        
                    ,;                                   :'         
                     .;.                               .l.          
                     .,:''.                        .','..,,         
                    :;'  .:l,''''............''''''..,. .;:,        
                    'c;.''       ............         .'.,.         
                      ,:.                                           

Installation

git clone https://github.com/godoctor/godoctor
cd godoctor && go install

For vim users see https://github.com/godoctor/godoctor.vim

Usage

It's recommended to use godoctor with an editor, though godoctor can be used directly.

$ godoctor

The godoctor command without any arguments provides usage information. For full documentation, see:

$ godoctor -doc

godoctor's People

Contributors

birdayz avatar joverbey avatar qulogic avatar rdallman avatar roberthorn avatar steffimariya avatar venkateshredy74 avatar wassimkha avatar wfrazier002 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

godoctor's Issues

Documentation Improvements

  • Extract Function's documentation is missing an example
  • "Scope" needs to be described somewhere, including how to set the scope from inside Vim

Plans for extract/inline refactorings?

I'm wondering if there are plans within the scope of this project for the following refactorings:

  • Extract local variable, package variable, const, or struct field from expression
  • Extract function or method from a group of statements/expressions
  • Inline variable or const or field
  • Inline function or method

help!i can not complie master

go mod tidy occurs error in master branch. it looks like below, i will be appriciate if it can be fix.

go get: github.com/willf/[email protected]: parsing go.mod:
module declares its path as: github.com/bits-and-blooms/bitset
but was required as: github.com/willf/bitset

Does it work with go modules?

I've set up a project with go modules (go 1.11 with GO11MODULES=on) and I can't get godoctor working there. When I let godoctor run it chokes on the modules, like:

Defaulting to package scope github.com/blah/blah/cmd for refactoring (provide an explicit scope to change this)
filter.go:6:2: Error: could not import github.com/cnkei/gospline (cannot find package "github.com/cnkei/gospline" in any of:
	/usr/lib/go-1.11/src/github.com/cnkei/gospline (from $GOROOT)
	/home/gru/go/src/github.com/cnkei/gospline (from $GOPATH))

Is there a way to make it work?

godoctor causing dockerfile build failure

I am using "go get -v -u github.com/godoctor/godoctor" in a dockerfile and getting a docker build failure at :

#18 22.56 go: downloading github.com/godoctor/godoctor v0.0.0-20200702010311-8433dcb3dc61
#18 22.92 go: downloading golang.org/x/tools v0.0.0-20191028215554-80f3f9ca0853
#18 22.92 go: downloading github.com/willf/bitset v1.1.10
#18 23.05 go: downloading github.com/willf/bitset v1.2.0
#18 23.54 go get: github.com/willf/[email protected] updating to
#18 23.54       github.com/willf/[email protected]: parsing go.mod:
#18 23.54       module declares its path as: github.com/bits-and-blooms/bitset
#18 23.54               but was required as: github.com/willf/bitset

Is there a fix or mitigation?

Dockerfile

RUN go get -v -u github.com/go-delve/delve/cmd/dlv \
    && go get -v -u github.com/mdempsky/gocode \
    && go get -v -u github.com/uudashr/gopkgs/v2/cmd/gopkgs \
    && go get -v -u github.com/ramya-rao-a/go-outline \
    && go get -v -u github.com/acroca/go-symbols \
    && go get -v -u golang.org/x/tools/cmd/guru \
    && go get -v -u golang.org/x/tools/cmd/gorename \
    && go get -v -u github.com/cweill/gotests/... \
    && go get -v -u github.com/fatih/gomodifytags \
    && go get -v -u github.com/josharian/impl \
    && go get -v -u github.com/davidrjenni/reftools/cmd/fillstruct \
    && go get -v -u github.com/haya14busa/goplay/cmd/goplay \
    && go get -v -u github.com/godoctor/godoctor \    
    && go get -v -u github.com/rogpeppe/godef \
    && go get -v -u github.com/sqs/goreturns \
    && go get -v -u golang.org/x/lint/golint \
    && go get -v -u github.com/zmb3/gogetdoc \    
    && go get -v -u honnef.co/go/tools/... \
    && go get -v -u golang.org/x/tools/cmd/goimports \
    && go get -v -u github.com/mgechev/revive

Logs:

#18 [14/17] RUN go get -v -u github.com/go-delve/delve/cmd/dlv     && go get -v -u github.com/mdempsky/gocode     && go get -v -u github.com/uudashr/gopkgs/v2/cmd/gopkgs     && go get -v -u github.com/ramya-rao-a/go-outline     && go get -v -u github.com/acroca/go-symbols     && go get -v -u golang.org/x/tools/cmd/guru     && go get -v -u golang.org/x/tools/cmd/gorename     && go get -v -u github.com/cweill/gotests/...     && go get -v -u github.com/fatih/gomodifytags     && go get -v -u github.com/josharian/impl     && go get -v -u github.com/davidrjenni/reftools/cmd/fillstruct     && go get -v -u github.com/haya14busa/goplay/cmd/goplay     && go get -v -u github.com/godoctor/godoctor     && go get -v -u github.com/rogpeppe/godef     && go get -v -u github.com/sqs/goreturns     && go get -v -u golang.org/x/lint/golint     && go get -v -u github.com/zmb3/gogetdoc     && go get -v -u honnef.co/go/tools/...     && go get -v -u golang.org/x/tools/cmd/goimports     && go get -v -u github.com/mgechev/revive
#18 sha256:5c0c506a58e2bcebe5aa151efc4dce315351188fc96ebccda965e3531a522c5f
#18 0.636 go: downloading github.com/go-delve/delve v1.6.1
#18 2.233 go: downloading github.com/sirupsen/logrus v1.6.0
#18 2.233 go: downloading github.com/spf13/cobra v0.0.0-20170417170307-b6cb39589372
#18 2.236 go: downloading github.com/mattn/go-isatty v0.0.3
#18 2.247 go: downloading gopkg.in/yaml.v2 v2.2.1
#18 2.258 go: downloading github.com/cosiner/argv v0.1.0
#18 2.260 go: downloading github.com/mattn/go-colorable v0.0.0-20170327083344-ded68f7a9561
#18 2.267 go: downloading github.com/peterh/liner v0.0.0-20170317030525-88609521dc4b
#18 2.338 go: downloading github.com/google/go-dap v0.5.0
#18 2.347 go: downloading github.com/mattn/go-isatty v0.0.13
#18 2.368 go: downloading github.com/sirupsen/logrus v1.8.1
#18 2.379 go: downloading github.com/mattn/go-colorable v0.1.8
#18 2.385 go: downloading golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae
#18 2.386 go: downloading github.com/spf13/cobra v1.1.3
#18 2.388 go: downloading gopkg.in/yaml.v2 v2.4.0
#18 2.391 go: downloading github.com/peterh/liner v1.2.1
#18 2.405 go: downloading go.starlark.net v0.0.0-20200821142938-949cc6f4b097
#18 2.434 go: downloading github.com/hashicorp/golang-lru v0.5.4
#18 2.439 go: downloading golang.org/x/arch v0.0.0-20190927153633-4e8777c89be4
#18 2.549 go: downloading github.com/konsorten/go-windows-terminal-sequences v1.0.3
#18 2.618 go: downloading github.com/cpuguy83/go-md2man v1.0.10
#18 2.692 go: downloading github.com/spf13/pflag v0.0.0-20170417173400-9e4c21054fa1
#18 2.723 go: downloading golang.org/x/arch v0.0.0-20210502124803-cbf565b21d1e
#18 2.723 go: downloading go.starlark.net v0.0.0-20210602144842-1cdb82c9e17a
#18 2.807 go: downloading golang.org/x/sys v0.0.0-20210603125802-9665404d3644
#18 2.810 go: downloading github.com/inconshreveable/mousetrap v1.0.0
#18 2.823 go: downloading github.com/russross/blackfriday v1.5.2
#18 2.828 go: downloading github.com/spf13/pflag v1.0.5
#18 2.963 go: downloading github.com/russross/blackfriday v1.6.0
#18 5.767 go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.0
#18 5.796 go: downloading github.com/mattn/go-runewidth v0.0.3
#18 5.861 go: downloading github.com/russross/blackfriday/v2 v2.0.1
#18 5.902 go: downloading github.com/mattn/go-runewidth v0.0.13
#18 6.008 go: downloading github.com/russross/blackfriday/v2 v2.1.0
#18 6.043 go: downloading github.com/shurcooL/sanitized_anchor_name v1.0.0
#18 6.144 go: downloading github.com/rivo/uniseg v0.2.0
#18 6.329 golang.org/x/sys/internal/unsafeheader
#18 6.331 github.com/rivo/uniseg
#18 6.341 github.com/hashicorp/golang-lru/simplelru
#18 6.344 go.starlark.net/internal/spell
#18 6.350 gopkg.in/yaml.v2
#18 6.350 golang.org/x/sys/unix
#18 6.351 github.com/go-delve/delve/pkg/goversion
#18 6.352 github.com/cosiner/argv
#18 6.357 github.com/go-delve/delve/pkg/astutil
#18 6.359 github.com/go-delve/delve/pkg/dwarf/util
#18 6.361 github.com/go-delve/delve/pkg/dwarf/regnum
#18 6.377 github.com/go-delve/delve/pkg/elfwriter
#18 6.378 github.com/go-delve/delve/pkg/version
#18 6.384 golang.org/x/arch/arm64/arm64asm
#18 6.391 golang.org/x/arch/x86/x86asm
#18 6.397 github.com/go-delve/delve/pkg/terminal/colorize
#18 6.400 github.com/go-delve/delve/pkg/dwarf/frame
#18 6.440 github.com/go-delve/delve/pkg/dwarf/op
#18 6.460 github.com/go-delve/delve/pkg/dwarf/line
#18 6.486 github.com/mattn/go-runewidth
#18 6.488 go.starlark.net/syntax
#18 6.589 github.com/peterh/liner
#18 6.596 github.com/google/go-dap
#18 6.671 github.com/go-delve/delve/pkg/dwarf/godwarf
#18 6.765 github.com/spf13/pflag
#18 6.818 github.com/russross/blackfriday/v2
#18 6.855 go.starlark.net/resolve
#18 6.925 github.com/go-delve/delve/pkg/dwarf/loclist
#18 6.926 github.com/go-delve/delve/pkg/dwarf/reader
#18 6.970 github.com/go-delve/delve/pkg/config
#18 6.986 github.com/mattn/go-isatty
#18 6.986 github.com/sirupsen/logrus
#18 6.996 go.starlark.net/internal/compile
#18 7.065 github.com/go-delve/delve/pkg/gobuild
#18 7.144 github.com/cpuguy83/go-md2man/v2/md2man
#18 7.149 go.starlark.net/starlark
#18 7.157 github.com/spf13/cobra
#18 7.159 github.com/go-delve/delve/pkg/logflags
#18 7.193 github.com/go-delve/delve/pkg/proc
#18 7.296 github.com/spf13/cobra/doc
#18 7.644 github.com/go-delve/delve/service/api
#18 7.644 github.com/go-delve/delve/pkg/proc/winutil
#18 7.644 github.com/go-delve/delve/pkg/proc/amd64util
#18 7.665 github.com/go-delve/delve/pkg/proc/core/minidump
#18 7.680 github.com/go-delve/delve/pkg/proc/linutil
#18 7.709 github.com/go-delve/delve/pkg/locspec
#18 7.734 github.com/go-delve/delve/pkg/proc/core
#18 7.734 github.com/go-delve/delve/pkg/proc/gdbserial
#18 7.734 github.com/go-delve/delve/pkg/proc/native
#18 7.896 github.com/go-delve/delve/service/debugger
#18 7.996 github.com/go-delve/delve/service
#18 8.023 github.com/go-delve/delve/service/rpc1
#18 8.023 github.com/go-delve/delve/service/rpc2
#18 8.097 github.com/go-delve/delve/service/rpccommon
#18 8.098 github.com/go-delve/delve/pkg/terminal/starbind
#18 8.233 github.com/go-delve/delve/pkg/terminal
#18 8.386 github.com/go-delve/delve/service/dap
#18 8.503 github.com/go-delve/delve/cmd/dlv/cmds
#18 8.561 github.com/go-delve/delve/cmd/dlv
#18 9.587 go: downloading github.com/mdempsky/gocode v0.0.0-20200405233807-4acdcbdea79d
#18 10.01 go: downloading golang.org/x/tools v0.1.2
#18 10.91 github.com/mdempsky/gocode/internal/lookdot
#18 10.91 golang.org/x/tools/go/internal/gcimporter
#18 10.93 github.com/mdempsky/gocode/internal/suggest
#18 11.10 golang.org/x/tools/go/gcexportdata
#18 11.12 github.com/mdempsky/gocode/internal/cache
#18 11.14 github.com/mdempsky/gocode/internal/gbimporter
#18 11.16 github.com/mdempsky/gocode
#18 11.67 go: downloading github.com/uudashr/gopkgs v1.3.2
#18 11.74 go: downloading github.com/uudashr/gopkgs/v2 v2.1.2
#18 11.77 go: downloading github.com/uudashr/gopkgs v2.0.1+incompatible
#18 11.82 go: downloading github.com/karrick/godirwalk v1.12.0
#18 11.82 go: downloading github.com/pkg/errors v0.8.1
#18 11.97 go: downloading github.com/pkg/errors v0.9.1
#18 11.97 go: downloading github.com/karrick/godirwalk v1.16.1
#18 12.08 github.com/pkg/errors
#18 12.08 github.com/karrick/godirwalk
#18 12.13 github.com/uudashr/gopkgs/v2
#18 12.15 github.com/uudashr/gopkgs/v2/cmd/gopkgs
#18 12.55 go: downloading github.com/ramya-rao-a/go-outline v0.0.0-20200117021646-2a048b4510eb
#18 12.76 golang.org/x/tools/go/buildutil
#18 12.80 github.com/ramya-rao-a/go-outline
#18 13.21 go: downloading github.com/acroca/go-symbols v0.1.1
#18 13.39 github.com/acroca/go-symbols
#18 13.70 go: downloading golang.org/x/sys v0.0.0-20210510120138-977fb7262007
#18 13.70 go: downloading golang.org/x/mod v0.4.2
#18 13.70 go: downloading golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
#18 14.13 golang.org/x/tools/cmd/guru/serial
#18 14.13 golang.org/x/mod/semver
#18 14.13 golang.org/x/xerrors/internal
#18 14.15 golang.org/x/tools/go/ast/astutil
#18 14.15 golang.org/x/sys/execabs
#18 14.15 golang.org/x/tools/internal/event/label
#18 14.16 golang.org/x/xerrors
#18 14.16 golang.org/x/tools/container/intsets
#18 14.16 golang.org/x/tools/internal/fastwalk
#18 14.16 golang.org/x/tools/internal/typesinternal
#18 14.16 golang.org/x/tools/refactor/importgraph
#18 14.18 golang.org/x/tools/go/internal/cgo
#18 14.18 golang.org/x/tools/internal/event/keys
#18 14.22 golang.org/x/mod/module
#18 14.22 golang.org/x/tools/internal/gopathwalk
#18 14.29 golang.org/x/tools/go/types/typeutil
#18 14.29 golang.org/x/tools/go/loader
#18 14.30 golang.org/x/tools/internal/event/core
#18 14.33 golang.org/x/tools/go/ssa
#18 14.33 golang.org/x/tools/internal/event
#18 14.36 golang.org/x/tools/internal/gocommand
#18 14.39 golang.org/x/tools/go/internal/packagesdriver
#18 14.39 golang.org/x/tools/internal/packagesinternal
#18 14.39 golang.org/x/tools/internal/imports
#18 14.41 golang.org/x/tools/go/packages
#18 14.66 golang.org/x/tools/imports
#18 14.74 golang.org/x/tools/go/callgraph
#18 14.74 golang.org/x/tools/go/ssa/ssautil
#18 14.77 golang.org/x/tools/go/pointer
#18 14.77 golang.org/x/tools/go/callgraph/static
#18 15.02 golang.org/x/tools/cmd/guru
#18 15.74 golang.org/x/tools/refactor/satisfy
#18 15.80 golang.org/x/tools/refactor/rename
#18 15.91 golang.org/x/tools/cmd/gorename
#18 16.28 go: downloading github.com/cweill/gotests v1.6.0
#18 16.37 go: downloading golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101
#18 17.52 github.com/cweill/gotests/internal/models
#18 17.54 github.com/cweill/gotests/internal/render/bindata
#18 17.54 github.com/cweill/gotests/templates
#18 17.56 github.com/cweill/gotests/internal/goparser
#18 17.56 github.com/cweill/gotests/internal/input
#18 17.59 github.com/cweill/gotests/internal/render
#18 17.61 github.com/cweill/gotests/internal/output
#18 17.63 github.com/cweill/gotests
#18 17.65 github.com/cweill/gotests/gotests/process
#18 17.66 github.com/cweill/gotests/gotests
#18 18.16 go: downloading github.com/fatih/gomodifytags v1.13.0
#18 18.28 go: downloading github.com/fatih/structtag v1.2.0
#18 18.28 go: downloading github.com/fatih/camelcase v1.0.0
#18 18.28 go: downloading golang.org/x/tools v0.0.0-20180824175216-6c1c5e93cdc1
#18 18.73 github.com/fatih/camelcase
#18 18.75 github.com/fatih/structtag
#18 18.76 github.com/fatih/gomodifytags
#18 19.07 go: downloading github.com/josharian/impl v1.0.0
#18 19.25 go: downloading golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375
#18 19.73 go: downloading golang.org/x/mod v0.2.0
#18 19.78 go: downloading golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
#18 19.95 github.com/josharian/impl
#18 20.38 go: downloading github.com/davidrjenni/reftools v0.0.0-20210213085015-40322ffdc2e4
#18 20.43 go: downloading golang.org/x/tools v0.0.0-20190408220357-e5b8258f4918
#18 21.16 github.com/davidrjenni/reftools/cmd/fillstruct
#18 21.63 go: downloading github.com/haya14busa/goplay v1.0.0
#18 21.78 go: downloading github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
#18 21.91 github.com/skratchdot/open-golang/open
#18 21.91 github.com/haya14busa/goplay
#18 21.94 github.com/haya14busa/goplay/cmd/goplay
#18 22.56 go: downloading github.com/godoctor/godoctor v0.0.0-20200702010311-8433dcb3dc61
#18 22.92 go: downloading golang.org/x/tools v0.0.0-20191028215554-80f3f9ca0853
#18 22.92 go: downloading github.com/willf/bitset v1.1.10
#18 23.05 go: downloading github.com/willf/bitset v1.2.0
#18 23.54 go get: github.com/willf/[email protected] updating to
#18 23.54       github.com/willf/[email protected]: parsing go.mod:
#18 23.54       module declares its path as: github.com/bits-and-blooms/bitset
#18 23.54               but was required as: github.com/willf/bitset
#18 ERROR: executor failed running [/bin/sh -c go get -v -u github.com/go-delve/delve/cmd/dlv     && go get -v -u github.com/mdempsky/gocode     && go get -v -u github.com/uudashr/gopkgs/v2/cmd/gopkgs     && go get -v -u github.com/ramya-rao-a/go-outline     && go get -v -u github.com/acroca/go-symbols     && go get -v -u golang.org/x/tools/cmd/guru     && go get -v -u golang.org/x/tools/cmd/gorename     && go get -v -u github.com/cweill/gotests/...     && go get -v -u github.com/fatih/gomodifytags     && go get -v -u github.com/josharian/impl     && go get -v -u github.com/davidrjenni/reftools/cmd/fillstruct     && go get -v -u github.com/haya14busa/goplay/cmd/goplay     && go get -v -u github.com/godoctor/godoctor     && go get -v -u github.com/rogpeppe/godef     && go get -v -u github.com/sqs/goreturns     && go get -v -u golang.org/x/lint/golint     && go get -v -u github.com/zmb3/gogetdoc     && go get -v -u honnef.co/go/tools/...     && go get -v -u golang.org/x/tools/cmd/goimports     && go get -v -u github.com/mgechev/revive]: exit code: 1

Extract Function failure - variable's previous value ignored

From issue #42 ...

I'm not sure if you would rather this were raised as a separate issue, but during my experimentation I discovered a situation where the extract function can produce incorrect code.
If you do a similar pattern where in the code you extract you modify a bool, then unless in that code you explicitly read the bool first then the current value of the bool is ignored.

package main

import (
	"fmt"
	"strings"
)

func main() {
	inputString := "bob"
	missingSuffix := true
	// If you extract this if
	// then it ignores the current value of missingSuffix
	if strings.Contains(inputString, "Suffix") {
		missingSuffix = false
	}

	fmt.Print("string:", inputString)
	if missingSuffix {
		fmt.Println(" is missing Suffix")
	} else {
		fmt.Println(" contains Suffix")
	}
}

Extracting the commented on if, gives you:

	missingSuffix = fred(inputString)


func fred(inputString string) bool {
	var missingSuffix bool
	if strings.Contains(inputString, "Suffix") {
		missingSuffix = false
	}
	return missingSuffix
}

Which will give you the incorrect result.

Add scope detection based on VCS root

i.e. we should be able to crawl up the directory structure until we find a .git, .hg, etc. (search tools such as "ag" seem to have these kinds of abilities) -- and then set the scope of the refactoring to that. to me it seems a sane default, as long as we can sanely find a vcs root (i.e. if we crawl up to / and find one there then it's a little weird / probably wrong). or we could likely use this detection in plugins (without having to write it in each plugin and set it manually). reverting back to how it is now would be easy enough for users to just do --scope ./, as opposed to the detection finding the scope dir to use requires a little more machinery.

I've found myself basically wanting this with regular use of the tool, as in general I'm not starting refactorings in the root directory of a repo, but I want refactorings to propagate across all packages affected in that repo (that may or may not be under my current root). It's of course possible for me to set scope on each refactoring, but it's a tad annoying since in general my editor state of setting the scope is short lived (i.e. I have short vim sessions).

it may also be nice to read in the .gitignore and ignore those files, too. I believe we're only loading in any .go files laying around so binaries and such are already being ignored, I guess this would handle extra .go files laying around that shouldn't be checked into vcs for whatever reason. don't think this is as important as the scope thing.

godoctor rename issue

Hi,

Rename stops working after a variable has been renamed to a single letter.

More details here: microamp/godoctor.el#10 (comment)

Switching between num and number works. But as soon as it's renamed to a single letter, say n, the next run of rename leads to the following error.

Defaulting to package scope github.com/microamp/godoctor-example for refactoring (provide an explicit scope to change this)
main.go:6:3: Error: Please select an identifier to rename. (Selected node: *ast.AssignStmt)

The issue is reproducible in Emacs. I'd like to know if it's reproducible in Vim too. Please ping me if you need more info. Cheers!

Named returns should be live at exit

Repro:

$ cd $GOPATH/src/golang.org/x/tools/imports
$ godoctor -scope . -file fastwalk_unix.go -pos 115,2:121,2 extract foo

Lines 115-121 are an if statement that assigns to a named return, name.

       // Special cases for common things:
       if nameLen == 1 && nameBuf[0] == '.' {
              name = "."
       } else if nameLen == 2 && nameBuf[0] == '.' && nameBuf[1] == '.' {
              name = ".."
       } else {
              name = string(nameBuf[:nameLen])
       }

When this if statement is extracted, the Extract Function refactoring does not detect that name is used after this block, so it makes it a local variable.

func foo(nameBuf *[1024]byte, nameLen int) {
	var name string
	if nameLen == 1 && nameBuf[0] == '.' {
		name = "."
	} else if nameLen == 2 && nameBuf[0] == '.' && nameBuf[1] == '.' {
		name = ".."
	} else {
		name = string(nameBuf[:nameLen])
	}
}

This is incorrect. The name variable is implicitly used at the function's exit since it is a named return, so it should be returned by the extracted function.

godoc refactoring adds unnecessary comment for types and ignores value declarations

The godoc refactoring currently adds a godoc comment to exported functions and types even when a valid godoc comment exists. This seems to be an issue where we're not properly configuring the AST parser to parse comments instead of the logic of the actual refactoring.

I've added a branch bug/godoc-adds-comment-when-existing with a failing test the demonstrates the issue.

Function Extract failure

Hi
Hopefully this isn't user error, but I've found a pattern I use in some of my code that seems to really upset the extract feature. In my tiddly test case I see an even weirder error where any attempt to extract anything says: "Error: invalid selection: An empty block cannot be extracted"
But when this pattern exists in my larger codebases the Extract function succeeds, but creates invalid variables that clash with the existing namespace.
Anyway, here's the noddy code:
`package main

import (
"fmt"
"strings"
)

func main() {
inputString := "bob"
listOfWork := []string{"a", "b", "c"}
var workDone bool

// This for loop can't seem to be extracted with any success
for _, wrk := range listOfWork {
if strings.Contains(inputString, wrk) {
workDone = true
inputString = strings.Replace(inputString, wrk, ".", -1)
}
}

if workDone {
fmt.Println("done something")
}
}
`

extract func writes full package name in types

an example below, from refactoring/extractfunc.go +376 with an extract called. need to whittle the types down to the basename, it seems like an updated version of the types package may be able to help, using a Qualifier func: https://godoc.org/golang.org/x/tools/go/types#TypeString . the vendored version we have doesn't offer the Qualifier.

// LocalsLiveAtEntry returns the local variables that are live at the
// entrypoint(s) to the selected region.
func (r *stmtRange) LocalsLiveAtEntry() []*types.Var {
        entryPoints := r.EntryPoints()

        liveEntry := r.hey(entryPoints)
        sort.Sort(typeVar(liveEntry))
        return liveEntry
}

func (r *stmtRange) hey(entryPoints []go/ast.Stmt) []*github.com/godoctor/godoctor/internal/golang.org/x/tools/go/types.Var {
var liveEntry []*github.com/godoctor/godoctor/internal/golang.org/x/tools/go/types.Var
liveEntry := []*types.Var{}
        for _, entry := range entryPoints {
                for variable, _ := range r.liveIn[entry] {
                        liveEntry = append(liveEntry, variable)
                }
        }
return liveEntry
}

Move away from version numbers?

@rdallman @roberthorn We've been giving version numbers to Go Doctor releases (we're at 0.3 now), but I'm wondering if we should move away from that. Basically, every time we bump the version number, I have to tag a commit, rebuild the documentation, and update the web site. Is there any advantage to that? As an alternative, we could just pull features into master one by one, and only update the documentation when it actually changes (same with the web site).

What do you think? If we move away from version numbers, can we somehow get "godoctor --help" to show the SHA-1 for the commit it was built from?

Is this tool actively mantained ?

Hi, we are planning to use this tool but it seems there is not much dev on it on fixing issues or new features.

So my question : is this repo actively mantained and is there a roadmap for it ?

go get godoctor fails with Go v1.5

go get github.com/godoctor/godoctor fails with the below message
package golang.org/x/tools/go/types: no buildable Go source files in <GOPATH>\src\golang.org\x\tools\go\types

go version is go version go1.5.4 windows/amd64

There is no failure while using go 1.6

Selection/offsets incorrect when cgo is used

When a file includes cgo code, the Go Doctor appears to map the user's selection to a completely incorrect AST node. This is because tokens' reported offsets do not correspond to the actual locations of the tokens in the original source file (probably due to cgo preprocessing). Tokens' line/column information is correct--it does match the original locations in the file--but the offsets appear to be quite different.

Can't rename struct fields

type Foo struct {
  messages []string
}

func NewFoo() *Foo {
  return &Foo{
    messages: []string{},
  }
}

Given the above, if my cursor is on either of the messages lines, and I invoke godoctor rename to rename messages to Messages for example, I get an error: Error: Please select an identifier to rename. (Selected node: *ast.KeyValueExpr) (the last part varies). I'd like to be able to rename struct fields as easily as identifiers

Tests are broken

Ever since #52, tests have been broken and do not compile. This makes it difficult to confirm everything is working as expected.

Also, please consider setting up some CI, which could have caught this before merging the PR.

OpenRefactory JSON protocol documentation is missing

Line 74 of INTERNALS says: "The OpenRefactory protocol is documented at FIXME: URL"

It would probably be best to add it to the repository, probably under engine/protocol (since that's where it's needed).

IIRC, there's a Word doc and a PDF. No harm in uploading both.

@roberthorn do you have this document? If not, I'm sure I do somewhere... have to search...

vim plugin improvements

  • selecting an entire line should normalize selection to the first & last valid chars (could be done in engine) instead of saying 'invalid selection'
  • should list possible arguments for each refactoring somehow, or have more robust error instead of "Invalid Arguments"
  • failed refactorings shouldn't edit the file (nit)

Extract Function should insert below extraction site, not at end of file

The Extract Function refactoring currently inserts the new function at the bottom of the file. Usually, it makes more sense to insert it immediately below the function from which the code is being extracted.

As an example, extracting the two lines from main should insert a new function /above/ five, not below it.

package main

import "fmt"

func main() {
    fmt.Println("Hello world")
    fmt.Println(five())
}

func five() int {
    return 5
}

Go Doctor interactive mode?

@rdallman @roberthorn I've been thinking about something, but I'm not sure it's actually worth doing.

Basically, I'm thinking about an "interactive mode" for Go Doctor, which would open a user interface allowing you to preview changes and decide whether or not to write them to disk.

One option would be a text-based UI, perhaps using https://github.com/nsf/termbox-go -- something like this ASCII art, except with colors/highlighting/etc.:

Fɪʟᴇꜱ & Mᴇꜱꜱᴀɢᴇꜱ (Ctrl+1)──────────────────────────────────────[ Gᴏ Dᴏᴄᴛᴏʀ ]
Defaulting to package scope github.com/whatever for refactoring (provide an ex…↑
_demos/editbox.go:9:6: Warning: tbprint redeclared in this block               ●
term.go                                                                        ·
stuff.go                                                                       ·
                                                                               ↓
Pʀᴇᴠɪᴇᴡ (Ctrl+2)────────────────────┬─────────────────────────────────────
1│package main                         │package main
2│func main() {                        │func renamed() {
3│}                                    │}
 │                                     │
 │                                     │
Ctrl+S Save & Edit • Esc Discard & Exit • Use ↑ ↓ ← → PgUp PgDn to scroll

Another option would be a GUI - e.g., https://mattn.github.io/go-gtk/

My hope would be that this could potentially replace the current Vim monstrosity, and maybe be useful in other editors. But something feels weird about having Vim (or Sublime, or whatever) open a tool with a totally separate GUI. So, idunno. Any thoughts?

it seems like go module cannot work with "Extract to function" in vscode

i'v set GO111MODULE="on", but when i use "extract to function", it will has these errors:
Defaulting to package scope ${path} for refactoring (provide an explicit scope to change this) ../../../../../github.com/gin-gonic/gin/binding/default_validator.go:11:2: Error: could not import github.com/go-playground/validator/v10 (cannot find package "github.com/go-playground/validator/v10" in any of: /usr/local/go/src/github.com/go-playground/validator/v10 (from $GOROOT) /home/${name}/go/src/github.com/go-playground/validator/v10 (from $GOPATH)).

why it didn't find module in ${GOPATH}/pkg/mod?

Rename bugs

  • Should not be allowed to rename a field/global var to init (“init: must be function”)
  • Given “r, ok :=“ Rename will not rename r to ok, but it spits out modifications to the file anyway
  • Some error messages need to be reworded/improved
  • Should only edit comments for enclosing function if local variable?

Line/column selections map columns incorrectly on non-ASCII input

The code to convert line/column selections to token.Pos objects (in text/selection.go) uses a FileSet (from the go/token package) to get a Position.Column, and then it searches for the first Pos with the correct line/column. However, when a line includes non-ASCII characters, the Position's Column does not map as expected: sequences of bytes corresponding to a single code point are given consecutive columns. In other words, Column seems to be more like the byte offset of that character within its line.

For now, both the Vim plug-in and the Web Demo pass offset/length pairs as a workaround.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.