Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
34 changes: 34 additions & 0 deletions internal/lsp/lsproto/_generate/generate.mts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,33 @@ const customStructures: Structure[] = [
],
documentation: "Parameters for the custom/setLogVerbosity notification.",
},
{
name: "ProjectFilesProject",
properties: [
{
name: "configFilePath",
type: { kind: "base", name: "string" },
documentation: "The absolute path to the config file (e.g. /path/to/tsconfig.json) for the project, or an empty string for an inferred project.",
},
{
name: "files",
type: { kind: "array", element: { kind: "base", name: "DocumentUri" } },
documentation: "The list of source file URIs in this project.",
},
],
documentation: "A project and its source files.",
},
{
name: "ProjectFilesResult",
properties: [
{
name: "projects",
type: { kind: "array", element: { kind: "reference", name: "ProjectFilesProject" } },
documentation: "The list of projects and their source files.",
},
],
documentation: "Result for the custom/projectFiles request.",
},
{
name: "PerformanceStatsTelemetryEvent",
properties: [
Expand Down Expand Up @@ -776,6 +803,13 @@ const customRequests: Request[] = [
messageDirection: "clientToServer",
documentation: "Returns project information (e.g. the tsconfig.json path) for a given text document.",
},
{
method: "custom/projectFiles",
typeName: "CustomProjectFilesRequest",
result: { kind: "reference", name: "ProjectFilesResult" },
messageDirection: "clientToServer",
documentation: "Returns all projects and the list of source files in each project.",
},
{
method: "custom/textDocument/sourceDefinition",
typeName: "CustomTextDocumentSourceDefinitionRequest",
Expand Down
140 changes: 140 additions & 0 deletions internal/lsp/lsproto/lsp_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ var handlers = sync.OnceValue(func() handlerMap {

registerRequestHandler(handlers, lsproto.CustomInitializeAPISessionInfo, (*Server).handleInitializeAPISession)
registerRequestHandler(handlers, lsproto.CustomProjectInfoInfo, (*Server).handleProjectInfo)
registerRequestHandler(handlers, lsproto.CustomProjectFilesInfo, (*Server).handleProjectFiles)
return handlers
})

Expand Down Expand Up @@ -1820,3 +1821,40 @@ func (s *Server) handleProjectInfo(ctx context.Context, params *lsproto.ProjectI
ConfigFilePath: configFilePath,
}, nil
}

func (s *Server) handleProjectFiles(_ context.Context, _ lsproto.NoParams, _ *lsproto.RequestMessage) (lsproto.CustomProjectFilesResponse, error) {
snapshot := s.session.Snapshot()
if snapshot == nil {
return &lsproto.ProjectFilesResult{
Projects: []*lsproto.ProjectFilesProject{},
}, nil
}

allProjects := snapshot.ProjectCollection.Projects()
result := make([]*lsproto.ProjectFilesProject, 0, len(allProjects))

for _, proj := range allProjects {
if proj.Program == nil {
continue
}
configFilePath := ""
if proj.Kind == project.KindConfigured {
configFilePath = proj.Name()
}
Comment on lines +1840 to +1843

sourceFiles := proj.Program.GetSourceFiles()
files := make([]lsproto.DocumentUri, 0, len(sourceFiles))
for _, sf := range sourceFiles {
files = append(files, lsconv.FileNameToDocumentURI(sf.FileName()))
}
Comment on lines +1845 to +1849

result = append(result, &lsproto.ProjectFilesProject{
ConfigFilePath: configFilePath,
Files: files,
})
}

return &lsproto.ProjectFilesResult{
Projects: result,
}, nil
}
Loading
Loading