prefs select option enhance
This commit is contained in:
parent
5ea21eb25f
commit
61ef48147b
45
conf/wide.go
45
conf/wide.go
|
@ -21,7 +21,6 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
@ -126,7 +125,7 @@ func checkEnv() {
|
|||
os.Exit(-1)
|
||||
}
|
||||
|
||||
gocode := Wide.GetExecutableInGOBIN("gocode")
|
||||
gocode := util.Go.GetExecutableInGOBIN("gocode")
|
||||
cmd = exec.Command(gocode, "close")
|
||||
_, err = cmd.Output()
|
||||
if nil != err {
|
||||
|
@ -135,7 +134,7 @@ func checkEnv() {
|
|||
glog.Warningf("Not found gocode [%s]", gocode)
|
||||
}
|
||||
|
||||
ide_stub := Wide.GetExecutableInGOBIN("ide_stub")
|
||||
ide_stub := util.Go.GetExecutableInGOBIN("ide_stub")
|
||||
cmd = exec.Command(ide_stub, "version")
|
||||
_, err = cmd.Output()
|
||||
if nil != err {
|
||||
|
@ -167,7 +166,7 @@ func (c *conf) GetUserWorkspace(username string) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
// GetGoFmt gets the path of Go format tool, returns "gofmt" if not found.
|
||||
// GetGoFmt gets the path of Go format tool, returns "gofmt" if not found "goimports".
|
||||
func (c *conf) GetGoFmt(username string) string {
|
||||
for _, user := range c.Users {
|
||||
if user.Name == username {
|
||||
|
@ -175,7 +174,7 @@ func (c *conf) GetGoFmt(username string) string {
|
|||
case "gofmt":
|
||||
return "gofmt"
|
||||
case "goimports":
|
||||
return c.GetExecutableInGOBIN("goimports")
|
||||
return util.Go.GetExecutableInGOBIN("goimports")
|
||||
default:
|
||||
glog.Errorf("Unsupported Go Format tool [%s]", user.GoFormat)
|
||||
return "gofmt"
|
||||
|
@ -210,42 +209,6 @@ func (*conf) GetUser(username string) *User {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetExecutableInGOBIN gets executable file under GOBIN path.
|
||||
//
|
||||
// The specified executable should not with extension, this function will append .exe if on Windows.
|
||||
func (*conf) GetExecutableInGOBIN(executable string) string {
|
||||
if util.OS.IsWindows() {
|
||||
executable += ".exe"
|
||||
}
|
||||
|
||||
gopaths := filepath.SplitList(os.Getenv("GOPATH"))
|
||||
|
||||
for _, gopath := range gopaths {
|
||||
// $GOPATH/bin/$GOOS_$GOARCH/executable
|
||||
ret := gopath + PathSeparator + "bin" + PathSeparator +
|
||||
os.Getenv("GOOS") + "_" + os.Getenv("GOARCH") + PathSeparator + executable
|
||||
if util.File.IsExist(ret) {
|
||||
return ret
|
||||
}
|
||||
|
||||
// $GOPATH/bin/{runtime.GOOS}_{runtime.GOARCH}/executable
|
||||
ret = gopath + PathSeparator + "bin" + PathSeparator +
|
||||
runtime.GOOS + "_" + runtime.GOARCH + PathSeparator + executable
|
||||
if util.File.IsExist(ret) {
|
||||
return ret
|
||||
}
|
||||
|
||||
// $GOPATH/bin/executable
|
||||
ret = gopath + PathSeparator + "bin" + PathSeparator + executable
|
||||
if util.File.IsExist(ret) {
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
// $GOBIN/executable
|
||||
return os.Getenv("GOBIN") + PathSeparator + executable
|
||||
}
|
||||
|
||||
// Save saves Wide configurations.
|
||||
func Save() bool {
|
||||
// just the Users field are volatile
|
||||
|
|
|
@ -67,7 +67,7 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// glog.Infof("offset: %d", offset)
|
||||
|
||||
gocode := conf.Wide.GetExecutableInGOBIN("gocode")
|
||||
gocode := util.Go.GetExecutableInGOBIN("gocode")
|
||||
argv := []string{"-f=json", "autocomplete", strconv.Itoa(offset)}
|
||||
|
||||
var output bytes.Buffer
|
||||
|
@ -144,7 +144,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
|
|||
glog.V(5).Infof("gocode set lib-path %s", libPath)
|
||||
|
||||
// FIXME: using gocode set lib-path has some issues while accrossing workspaces
|
||||
gocode := conf.Wide.GetExecutableInGOBIN("gocode")
|
||||
gocode := util.Go.GetExecutableInGOBIN("gocode")
|
||||
argv := []string{"set", "lib-path", libPath}
|
||||
exec.Command(gocode, argv...).Run()
|
||||
|
||||
|
@ -213,7 +213,7 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// glog.Infof("offset [%d]", offset)
|
||||
|
||||
ide_stub := conf.Wide.GetExecutableInGOBIN("ide_stub")
|
||||
ide_stub := util.Go.GetExecutableInGOBIN("ide_stub")
|
||||
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-info", "."}
|
||||
cmd := exec.Command(ide_stub, argv...)
|
||||
cmd.Dir = curDir
|
||||
|
@ -284,7 +284,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// glog.Infof("offset [%d]", offset)
|
||||
|
||||
ide_stub := conf.Wide.GetExecutableInGOBIN("ide_stub")
|
||||
ide_stub := util.Go.GetExecutableInGOBIN("ide_stub")
|
||||
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-def", "."}
|
||||
cmd := exec.Command(ide_stub, argv...)
|
||||
cmd.Dir = curDir
|
||||
|
@ -363,7 +363,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
|
|||
offset := getCursorOffset(code, line, ch)
|
||||
// glog.Infof("offset [%d]", offset)
|
||||
|
||||
ide_stub := conf.Wide.GetExecutableInGOBIN("ide_stub")
|
||||
ide_stub := util.Go.GetExecutableInGOBIN("ide_stub")
|
||||
argv := []string{"type", "-cursor", filename + ":" + strconv.Itoa(offset), "-use", "."}
|
||||
cmd := exec.Command(ide_stub, argv...)
|
||||
cmd.Dir = curDir
|
||||
|
|
|
@ -59,7 +59,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
|
|||
if "GET" == r.Method {
|
||||
model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(user.Locale), "user": user,
|
||||
"ver": conf.WideVersion, "goos": runtime.GOOS, "goarch": runtime.GOARCH, "gover": runtime.Version(),
|
||||
"locales": i18n.GetLocalesNames()}
|
||||
"locales": i18n.GetLocalesNames(), "gofmts": util.Go.GetGoFormats()}
|
||||
|
||||
t, err := template.ParseFiles("views/preference.html")
|
||||
|
||||
|
|
|
@ -287,9 +287,16 @@ var menu = {
|
|||
$("#dialogPreference").load('/preference', function () {
|
||||
$("#localeSelect").on('change', function () {
|
||||
var $dialogPreference = $("#dialogPreference"),
|
||||
$locale = $dialogPreference.find("input[name=locale]")
|
||||
$input = $dialogPreference.find("input[name=locale]")
|
||||
|
||||
$locale.val(this.value);
|
||||
$input.val(this.value);
|
||||
});
|
||||
|
||||
$("#goFmtSelect").on('change', function () {
|
||||
var $dialogPreference = $("#dialogPreference"),
|
||||
$input = $dialogPreference.find("input[name=goFmt]")
|
||||
|
||||
$input.val(this.value);
|
||||
});
|
||||
|
||||
$("#dialogPreference input").keyup(function () {
|
||||
|
|
54
util/go.go
54
util/go.go
|
@ -19,6 +19,12 @@ import (
|
|||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
PathSeparator = string(os.PathSeparator) // OS-specific path separator
|
||||
PathListSeparator = string(os.PathListSeparator) // OS-specific path list separator
|
||||
)
|
||||
|
||||
type mygo struct{}
|
||||
|
@ -45,3 +51,51 @@ func (*mygo) IsAPI(path string) bool {
|
|||
|
||||
return strings.HasPrefix(path, apiPath)
|
||||
}
|
||||
|
||||
// GetGoFormats gets Go format tools. It may return ["gofmt", "goimports"].
|
||||
func (*mygo) GetGoFormats() []string {
|
||||
ret := []string {"gofmt"}
|
||||
|
||||
p := Go.GetExecutableInGOBIN("goimports")
|
||||
if File.IsExist(p) {
|
||||
ret = append(ret, "goimports")
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
// GetExecutableInGOBIN gets executable file under GOBIN path.
|
||||
//
|
||||
// The specified executable should not with extension, this function will append .exe if on Windows.
|
||||
func (*mygo) GetExecutableInGOBIN(executable string) string {
|
||||
if OS.IsWindows() {
|
||||
executable += ".exe"
|
||||
}
|
||||
|
||||
gopaths := filepath.SplitList(os.Getenv("GOPATH"))
|
||||
|
||||
for _, gopath := range gopaths {
|
||||
// $GOPATH/bin/$GOOS_$GOARCH/executable
|
||||
ret := gopath + PathSeparator + "bin" + PathSeparator +
|
||||
os.Getenv("GOOS") + "_" + os.Getenv("GOARCH") + PathSeparator + executable
|
||||
if File.IsExist(ret) {
|
||||
return ret
|
||||
}
|
||||
|
||||
// $GOPATH/bin/{runtime.GOOS}_{runtime.GOARCH}/executable
|
||||
ret = gopath + PathSeparator + "bin" + PathSeparator +
|
||||
runtime.GOOS + "_" + runtime.GOARCH + PathSeparator + executable
|
||||
if File.IsExist(ret) {
|
||||
return ret
|
||||
}
|
||||
|
||||
// $GOPATH/bin/executable
|
||||
ret = gopath + PathSeparator + "bin" + PathSeparator + executable
|
||||
if File.IsExist(ret) {
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
// $GOBIN/executable
|
||||
return os.Getenv("GOBIN") + PathSeparator + executable
|
||||
}
|
||||
|
|
|
@ -41,8 +41,15 @@
|
|||
<div class="fn-none" data-index="gotool">
|
||||
<label>
|
||||
{{.i18n.go_format}}{{.i18n.colon}}
|
||||
<input data-value="{{.user.GoFormat}}" value="{{.user.GoFormat}}" name="goFmt"/>
|
||||
<br/>
|
||||
<select class="select" id="goFmtSelect">
|
||||
{{range $index, $gofmt := .gofmts }}
|
||||
<option name="{{$gofmt}}" value="{{$gofmt}}" {{if eq $.user.GoFormat $gofmt}}selected="selected"{{end}}>{{$gofmt}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
<br/>
|
||||
</label>
|
||||
<input data-value="{{.user.GoFormat}}" value="{{.user.GoFormat}}" name="goFmt" hidden="hidden" />
|
||||
</div>
|
||||
<div class="fn-none" data-index="user">
|
||||
<label>
|
||||
|
@ -50,7 +57,7 @@
|
|||
<br/>
|
||||
<select class="select" id="localeSelect">
|
||||
{{range $index, $localeName := .locales }}
|
||||
<option name="locale" value="{{$localeName}}" {{if eq $.user.Locale $localeName}}selected="selected"{{end}}>{{$localeName}}</option>
|
||||
<option name="{{$localeName}}" value="{{$localeName}}" {{if eq $.user.Locale $localeName}}selected="selected"{{end}}>{{$localeName}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
<br/>
|
||||
|
|
Loading…
Reference in New Issue