Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ulsp/config/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ monorepos:
_default:
scip:
loadFromDirectories: true
# Uncomment below as needed to enable language-specific language features for this repository
# languages:
# - java
directories:
- '.scip'

Expand Down
4 changes: 4 additions & 0 deletions src/ulsp/controller/indexer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ go_library(
"@com_github_gofrs_uuid//:go_default_library",
"@com_github_uber_go_tally//:go_default_library",
"@dev_lsp_go_protocol//:go_default_library",
"@org_uber_go_config//:go_default_library",
"@org_uber_go_fx//:go_default_library",
"@org_uber_go_zap//:go_default_library",
],
Expand All @@ -46,7 +47,9 @@ go_test(
"//src/ulsp/factory:go_default_library",
"//src/ulsp/gateway/ide-client:go_ideclient_gomock_library",
"//src/ulsp/internal/executor:go_loader_gomock_library",
"//src/ulsp/internal/fs:go_default_library",
"//src/ulsp/internal/fs:go_fs_gomock_library",
"//src/ulsp/internal/fs/fsmock/helpers:go_default_library",
"//src/ulsp/internal/logfilewriter:go_default_library",
"//src/ulsp/internal/serverinfofile:go_serverinfofile_gomock_library",
"//src/ulsp/repository/session:go_repository_gomock_library",
Expand All @@ -55,6 +58,7 @@ go_test(
"@com_github_stretchr_testify//require:go_default_library",
"@com_github_uber_go_tally//:go_default_library",
"@dev_lsp_go_protocol//:go_default_library",
"@org_uber_go_config//:go_default_library",
"@org_uber_go_fx//fxtest:go_default_library",
"@org_uber_go_mock//gomock:go_default_library",
"@org_uber_go_zap//:go_default_library",
Expand Down
35 changes: 25 additions & 10 deletions src/ulsp/controller/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package indexer
import (
"context"
"fmt"
"go.uber.org/config"
"io"
"path/filepath"
"slices"
"strings"

"github.com/gofrs/uuid"
Expand All @@ -25,8 +27,8 @@ import (
)

const (
_javaLang = "java"
_nameKey = "indexer"
_fievel = "fievel"
_syncMessage = "Syncing index for file: %s"
)

Expand All @@ -50,6 +52,7 @@ type Params struct {

Sessions session.Repository
Logger *zap.SugaredLogger
Config config.Provider
Documents docsync.Controller
Guidance userguidance.Controller
Stats tally.Scope
Expand All @@ -68,6 +71,7 @@ type Controller interface {
type controller struct {
sessions session.Repository
logger *zap.SugaredLogger
config entity.MonorepoConfigs
documents docsync.Controller
executor executor.Executor
ideGateway ideclient.Gateway
Expand All @@ -81,9 +85,15 @@ type controller struct {

// New controller for indexer
func New(p Params) Controller {
configs := entity.MonorepoConfigs{}
if err := p.Config.Get(entity.MonorepoConfigKey).Populate(&configs); err != nil {
panic(fmt.Sprintf("getting configuration for %q: %v", entity.MonorepoConfigKey, err))
}

c := &controller{
sessions: p.Sessions,
logger: p.Logger.With("plugin", _nameKey),
config: configs,
documents: p.Documents,
executor: p.Executor,
ideGateway: p.IdeGateway,
Expand Down Expand Up @@ -128,13 +138,18 @@ func (c *controller) StartupInfo(ctx context.Context) (ulspplugin.PluginInfo, er
WorkDoneProgressCancel: c.workDoneProgressCancel,
}

relevantRepos := make(map[entity.MonorepoName]struct{})
for monorepoName, monorepoConfig := range c.config {
if slices.Contains(monorepoConfig.Languages, _javaLang) {
relevantRepos[monorepoName] = struct{}{}
}
}

return ulspplugin.PluginInfo{
Priorities: priorities,
Methods: methods,
NameKey: _nameKey,
RelevantRepos: map[entity.MonorepoName]struct{}{
entity.MonorepoNameJava: {},
},
Priorities: priorities,
Methods: methods,
NameKey: _nameKey,
RelevantRepos: relevantRepos,
}, nil
}

Expand All @@ -148,16 +163,16 @@ func (c *controller) initialize(ctx context.Context, params *protocol.Initialize
c.indexer = make(map[uuid.UUID]Indexer)
}

// only support fievel indexer for java monorepo now
if strings.HasSuffix(s.WorkspaceRoot, _fievel) {
// Indexer is currently only supported in Java monorepositories
if slices.Contains(c.config[s.Monorepo].Languages, _javaLang) {
if c.indexerOutputWriter == nil {
var err error
c.indexerOutputWriter, err = logfilewriter.SetupOutputWriter(c.outputWriterParams, _logFileKey)
if err != nil {
return fmt.Errorf("setting up log file: %w", err)
}
}
c.indexer[s.UUID] = NewJavaIndexer(s, c.indexerOutputWriter)
c.indexer[s.UUID] = NewJavaIndexer(c.outputWriterParams.FS, s, c.indexerOutputWriter)
}
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions src/ulsp/controller/indexer/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package indexer
import (
"context"
"fmt"
"go.uber.org/config"
"os"
"testing"

Expand All @@ -25,10 +26,12 @@ import (
)

func TestNew(t *testing.T) {
mockConfig, _ := config.NewStaticProvider(map[string]interface{}{})
assert.NotPanics(t, func() {
New(Params{
Logger: zap.NewNop().Sugar(),
Stats: tally.NewTestScope("testing", make(map[string]string, 0)),
Config: mockConfig,
})
})
}
Expand Down Expand Up @@ -65,8 +68,15 @@ func TestInitialize(t *testing.T) {
fs.EXPECT().MkdirAll(gomock.Any()).Return(nil)
fs.EXPECT().TempFile(gomock.Any(), gomock.Any()).Return(tempFile, nil)

monorepoConfig := entity.MonorepoConfigs{
"": {
Languages: []string{"java"},
},
}

c := controller{
sessions: sessionRepository,
config: monorepoConfig,
outputWriterParams: logfilewriter.Params{
Lifecycle: fxtest.NewLifecycle(t),
ServerInfoFile: infoFile,
Expand Down
7 changes: 5 additions & 2 deletions src/ulsp/controller/indexer/java_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package indexer
import (
"context"
"fmt"
"github.com/uber/scip-lsp/src/ulsp/internal/fs"
"io"
"os/exec"
"path"
Expand All @@ -26,16 +27,18 @@ type javaIndexer struct {
path string
session *entity.Session
outputWriter io.Writer
fs fs.UlspFS
}

// NewJavaIndexer return a new java indexer
func NewJavaIndexer(s *entity.Session, outputWriter io.Writer) Indexer {
func NewJavaIndexer(fs fs.UlspFS, s *entity.Session, outputWriter io.Writer) Indexer {
indexerPath := path.Join(s.WorkspaceRoot, _javaIndexerRelativePath)

return &javaIndexer{
session: s,
path: indexerPath,
outputWriter: outputWriter,
fs: fs,
}
}

Expand Down Expand Up @@ -73,7 +76,7 @@ func (j *javaIndexer) IsRelevantDocument(document protocol.TextDocumentItem) boo
// GetUniqueIndexKey returns a unique key for the document,
// this will be used to determine if additional relevant indexing is in progress for this document
func (j *javaIndexer) GetUniqueIndexKey(document protocol.TextDocumentItem) (string, error) {
target, err := javautils.GetJavaTarget(j.session.WorkspaceRoot, document.URI)
target, err := javautils.GetJavaTarget(j.fs, j.session.WorkspaceRoot, document.URI)
if err != nil {
return "", err
}
Expand Down
25 changes: 21 additions & 4 deletions src/ulsp/controller/indexer/java_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package indexer
import (
"context"
"fmt"
ulspfs "github.com/uber/scip-lsp/src/ulsp/internal/fs"
"github.com/uber/scip-lsp/src/ulsp/internal/fs/fsmock"
"github.com/uber/scip-lsp/src/ulsp/internal/fs/fsmock/helpers"
"io"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -26,7 +30,7 @@ func TestJavaIndexerSyncIndex(t *testing.T) {
doc := protocol.TextDocumentItem{
URI: protocol.DocumentURI("file:///home/fievel/sample.java"),
}
indexer := NewJavaIndexer(s, io.Discard)
indexer := NewJavaIndexer(ulspfs.New(), s, io.Discard)

t.Run("success", func(t *testing.T) {
executorMock := executormock.NewMockExecutor(ctrl)
Expand All @@ -53,7 +57,7 @@ func TestJavaIndexerNewJavaIndexer(t *testing.T) {
UUID: factory.UUID(),
}
s.WorkspaceRoot = "/home/fievel"
indexer := NewJavaIndexer(s, io.Discard)
indexer := NewJavaIndexer(ulspfs.New(), s, io.Discard)
assert.NotNil(t, indexer)
}

Expand All @@ -62,7 +66,7 @@ func TestJavaIndexerIsRelevantDocument(t *testing.T) {
UUID: factory.UUID(),
}
s.WorkspaceRoot = "/home/fievel"
indexer := NewJavaIndexer(s, io.Discard)
indexer := NewJavaIndexer(ulspfs.New(), s, io.Discard)

t.Run("success java", func(t *testing.T) {
doc := protocol.TextDocumentItem{
Expand Down Expand Up @@ -95,9 +99,17 @@ func TestJavaIndexerGetUniqueIndexKey(t *testing.T) {
}
s.WorkspaceRoot = "/home/user/fievel"
s.UUID = factory.UUID()
indexer := NewJavaIndexer(s, io.Discard)

t.Run("success", func(t *testing.T) {
ctrl := gomock.NewController(t)
fs := fsmock.NewMockUlspFS(ctrl)

fs.EXPECT().DirExists(gomock.Any()).Return(true, nil)
fs.EXPECT().ReadDir("/home/user/fievel/tooling/intellij").Return([]os.DirEntry{helpers.MockDirEntry("BUILD.bazel", false)}, nil)
fs.EXPECT().ReadDir(gomock.Any()).Times(4).Return([]os.DirEntry{}, nil)

indexer := NewJavaIndexer(fs, s, io.Discard)

validDoc := protocol.TextDocumentItem{
URI: "file:///home/user/fievel/tooling/intellij/src/intellij/bazel/BazelSyncListener.java",
}
Expand All @@ -108,6 +120,11 @@ func TestJavaIndexerGetUniqueIndexKey(t *testing.T) {
})

t.Run("failure", func(t *testing.T) {
ctrl := gomock.NewController(t)
fs := fsmock.NewMockUlspFS(ctrl)

indexer := NewJavaIndexer(fs, s, io.Discard)

invalidDoc := protocol.TextDocumentItem{
URI: "file:///home/user/BazelSyncListener.java",
}
Expand Down
1 change: 1 addition & 0 deletions src/ulsp/controller/quick-actions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ go_library(
"//src/ulsp/gateway/ide-client:go_default_library",
"//src/ulsp/internal/errors:go_default_library",
"//src/ulsp/internal/executor:go_default_library",
"//src/ulsp/internal/fs:go_default_library",
"//src/ulsp/mapper:go_default_library",
"//src/ulsp/repository/session:go_default_library",
"@com_github_gofrs_uuid//:go_default_library",
Expand Down
1 change: 1 addition & 0 deletions src/ulsp/controller/quick-actions/action/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ go_library(
"//src/ulsp/entity:go_default_library",
"//src/ulsp/gateway/ide-client:go_default_library",
"//src/ulsp/internal/executor:go_default_library",
"//src/ulsp/internal/fs:go_default_library",
"//src/ulsp/repository/session:go_default_library",
"@dev_lsp_go_protocol//:go_default_library",
],
Expand Down
2 changes: 2 additions & 0 deletions src/ulsp/controller/quick-actions/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package quickactions
import (
"context"
"encoding/json"
"github.com/uber/scip-lsp/src/ulsp/internal/fs"

"github.com/uber/scip-lsp/src/ulsp/entity"
ideclient "github.com/uber/scip-lsp/src/ulsp/gateway/ide-client"
Expand All @@ -25,6 +26,7 @@ type ExecuteParams struct {
IdeGateway ideclient.Gateway
Executor executor.Executor
ProgressToken *protocol.ProgressToken
FileSystem fs.UlspFS
}

// ProgressInfoParams provides parameters for display during progress of action in status bar
Expand Down
2 changes: 2 additions & 0 deletions src/ulsp/controller/quick-actions/actions-java/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ go_test(
"//src/ulsp/factory:go_default_library",
"//src/ulsp/gateway/ide-client:go_ideclient_gomock_library",
"//src/ulsp/internal/executor:go_loader_gomock_library",
"//src/ulsp/internal/fs:go_fs_gomock_library",
"//src/ulsp/internal/fs/fsmock/helpers:go_default_library",
"//src/ulsp/mapper:go_default_library",
"//src/ulsp/repository/session:go_repository_gomock_library",
"@com_github_stretchr_testify//assert:go_default_library",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (a *ActionJavaBuild) Execute(ctx context.Context, params *action.ExecutePar
if err != nil {
return fmt.Errorf("getting writer: %w", err)
}
target, err := javautils.GetJavaTarget(s.WorkspaceRoot, resultArgs.Document.URI)
target, err := javautils.GetJavaTarget(params.FileSystem, s.WorkspaceRoot, resultArgs.Document.URI)
if err != nil {
return err
}
Expand Down Expand Up @@ -149,7 +149,7 @@ func (a *ActionJavaBuild) ProvideWorkDoneProgressParams(ctx context.Context, par
}

file := path.Base(resultArgs.Document.URI.Filename())
target, err := javautils.GetJavaTarget(s.WorkspaceRoot, resultArgs.Document.URI)
target, err := javautils.GetJavaTarget(params.FileSystem, s.WorkspaceRoot, resultArgs.Document.URI)
if err != nil {
return nil, err
}
Expand Down
Loading
Loading