forked from golang/tools
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
580 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# Add no patterns to .gitignore except for files generated by the build. | ||
last-change | ||
|
||
go.work* | ||
log.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2022 The GoPlus Authors (goplus.org). All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"golang.org/x/tools/gopls/goxls/proxy" | ||
) | ||
|
||
func main() { | ||
proxy.Main() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2022 The GoPlus Authors (goplus.org). All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import "golang.org/x/tools/gopls/goxls" | ||
|
||
func main() { | ||
goxls.Main() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2022 The GoPlus Authors (goplus.org). All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package proxy | ||
|
||
import ( | ||
"io" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
const ( | ||
gopls = "gopls.origin" | ||
) | ||
|
||
func Main() { | ||
home, err := os.UserHomeDir() | ||
check(err) | ||
|
||
goplsDir := home + "/.gopls" | ||
rotateDir := goplsDir + "/" + strconv.FormatInt(time.Now().UnixMicro(), 36) | ||
err = os.MkdirAll(rotateDir, 0755) | ||
check(err) | ||
|
||
createFile := func(name string) (f *os.File, err error) { | ||
normal, rotate := goplsDir+name, rotateDir+name | ||
os.Rename(normal, rotate) | ||
return os.Create(normal) | ||
} | ||
|
||
logf, err := createFile("/gopls.log") | ||
check(err) | ||
defer logf.Close() | ||
|
||
stdinf, err := createFile("/gopls.in") | ||
check(err) | ||
defer stdinf.Close() | ||
|
||
stdoutf, err := createFile("/gopls.out") | ||
check(err) | ||
defer stdoutf.Close() | ||
|
||
stderrf, err := createFile("/gopls.err") | ||
check(err) | ||
defer stderrf.Close() | ||
|
||
log.SetOutput(logf) | ||
log.Println("[INFO] app start:", os.Args) | ||
|
||
pr, pw, err := os.Pipe() | ||
check(err) | ||
go func() { | ||
w := io.MultiWriter(pw, stdinf) | ||
for { | ||
io.Copy(w, os.Stdin) | ||
} | ||
}() | ||
|
||
cmd := exec.Command(gopls, os.Args[1:]...) | ||
cmd.Stdin = pr | ||
cmd.Stdout = io.MultiWriter(os.Stdout, stdoutf) | ||
cmd.Stderr = io.MultiWriter(os.Stderr, stderrf) | ||
err = cmd.Run() | ||
check(err) | ||
} | ||
|
||
func check(err error) { | ||
if err != nil { | ||
log.Panicln(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2023 The GoPlus Authors (goplus.org). All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package packages | ||
|
||
import ( | ||
"bytes" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/goplus/gop" | ||
"github.com/goplus/gop/x/gopprojs" | ||
) | ||
|
||
var ( | ||
gopInstalled bool | ||
) | ||
|
||
const ( | ||
debugGop = false | ||
) | ||
|
||
func init() { | ||
go initGop() | ||
} | ||
|
||
func initGop() { | ||
var b bytes.Buffer | ||
cmd := exec.Command("gop", "env", "GOPROOT") | ||
cmd.Stdout = &b | ||
err := cmd.Run() | ||
if gopRoot := b.String(); err == nil && gopRoot != "" { | ||
os.Setenv("GOPROOT", strings.TrimRight(gopRoot, "\n\r")) | ||
gopInstalled = true | ||
} else if debugGop { | ||
log.Panicln("FATAL: gop not installed") | ||
} | ||
} | ||
|
||
func GenGo(pattern ...string) (err error) { | ||
if !gopInstalled { | ||
return nil | ||
} | ||
projs, err := gopprojs.ParseAll(pattern...) | ||
if err != nil { | ||
return | ||
} | ||
for _, proj := range projs { | ||
switch v := proj.(type) { | ||
case *gopprojs.DirProj: | ||
_, _, err = gop.GenGo(v.Dir, nil, true) | ||
case *gopprojs.PkgPathProj: | ||
if v.Path == "builtin" { | ||
continue | ||
} | ||
_, _, err = gop.GenGoPkgPath("", v.Path, nil, true) | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.