buildserver

package
v0.0.0-...-75b7e41 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2024 License: MIT Imports: 46 Imported by: 0

Documentation

Overview

Package buildserver is an LSP-compatible build server for Go. It wraps an LSP language server and transparently fetches dependencies and rewrites file URIs to fit the Go directory structure scheme.

Index

Constants

This section is empty.

Variables

View Source
var Debug = true

Debug if true will cause extra logging information to be printed

View Source
var NewDepRepoVFS = func(ctx context.Context, cloneURL *url.URL, rev string, zipURLTemplate *string) (ctxvfs.FileSystem, error) {
	if zipURLTemplate != nil {
		zipURL := fmt.Sprintf(*zipURLTemplate, path.Join(cloneURL.Host, cloneURL.Path), rev)
		archive, err := vfsutil.NewZipVFS(ctx, zipURL, depZipFetch.Inc, depZipFetchFailed.Inc, false)
		if archive != nil && err == nil {
			return archive, nil
		}

		if strings.HasSuffix(cloneURL.Path, ".git") {
			zipURL := fmt.Sprintf(*zipURLTemplate, path.Join(cloneURL.Host, strings.TrimSuffix(cloneURL.Path, ".git")), rev)
			archive, err := vfsutil.NewZipVFS(ctx, zipURL, depZipFetch.Inc, depZipFetchFailed.Inc, false)
			if archive != nil && err == nil {
				return archive, nil
			}
		}
	}

	if cloneURL.Host == "github.com" {
		fullName := cloneURL.Host + strings.TrimSuffix(cloneURL.Path, ".git")
		archive, err := vfsutil.NewGitHubRepoVFS(ctx, fullName, rev)
		if archive != nil && err == nil {
			return archive, nil
		}
	}

	return &vfsutil.GitRepoVFS{
		CloneURL: cloneURL.String(),
		Rev:      rev,
	}, nil
}

NewDepRepoVFS returns a virtual file system interface for accessing the files in the specified repo at the given commit. The returned VFS is always backed by a zip archive in memory. The following sources are tried in sequence, and the first one that has the repo is used:

1. A zip URL built from the template string passed via `initializationOptions.zipURLTemplate` 2. GitHub's codeload endpoint 3. A full `git clone` followed by `git archive --format=zip <rev>`

Source 1 and 2 are performance optimizations over cloning the whole repo.

View Source
var RemoteFS = func(ctx context.Context, initializeParams lspext.InitializeParams) (ctxvfs.FileSystem, io.Closer, error) {
	zipURL := func() string {
		initializationOptions, ok := initializeParams.InitializationOptions.(map[string]interface{})
		if !ok {
			return ""
		}
		zipURL, _ := initializationOptions["zipURL"].(string)
		if zipURL != "" {
			return zipURL
		}
		zipURLTemplate, _ := initializationOptions["zipURLTemplate"].(string)
		if zipURLTemplate == "" {
			return ""
		}
		root, err := url.Parse(string(initializeParams.OriginalRootURI))
		if err != nil {
			return ""
		}
		return fmt.Sprintf(zipURLTemplate, path.Join(root.Host, root.Path), root.RawQuery)
	}()
	if zipURL != "" {
		vfs, err := vfsutil.NewZipVFS(ctx, zipURL, zipFetch.Inc, zipFetchFailed.Inc, true)
		return vfs, vfs, err
	}
	return nil, ioutil.NopCloser(strings.NewReader("")), errors.Errorf("no zipURL was provided in the initializationOptions")
}

RemoteFS fetches a zip archive from the URL specified in the zipURL field of the initializationOptions and returns a virtual file system interface for accessing the files in the specified repo at the given commit.

SECURITY NOTE: This DOES NOT check that the user or context has permissions to read the repo. We assume permission checks happen before a request reaches a build server.

Functions

func FetchCommonDeps

func FetchCommonDeps()

FetchCommonDeps will fetch our common used dependencies. This is to avoid impacting the first ever typecheck we do in a repo since it will have to fetch the dependency from the internet.

Types

type BuildHandler

type BuildHandler struct {
	langserver.HandlerCommon
	*langserver.HandlerShared
	// contains filtered or unexported fields
}

BuildHandler is a Go build server LSP/JSON-RPC handler that wraps a Go language server handler.

func NewHandler

func NewHandler(defaultCfg langserver.Config) *BuildHandler

NewHandler creates a new build server wrapping a (also newly created) Go language server. I.e., it creates a BuildHandler wrapping a LangHandler. The two handlers share a file system (in memory).

The build server is responsible for things such as fetching dependencies, setting up the right file system structure and paths, and mapping local file system paths to logical URIs (e.g., /goroot/src/fmt/print.go -> git://github.com/golang/go?go1.7.1#src/fmt/print.go).

func (*BuildHandler) Close

func (h *BuildHandler) Close() error

Close implements io.Closer

func (*BuildHandler) Handle

func (h *BuildHandler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL