Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support folders with only a main.pony #9

Merged
merged 2 commits into from
Dec 1, 2024
Merged
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
11 changes: 9 additions & 2 deletions lsp/test/_workspace_tests.pony
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ class \nodoc\ iso _RouterFindTest is UnitTest
})
let scanner = WorkspaceScanner.create(channel)
let workspaces = scanner.scan(file_auth, this_dir_path)
h.assert_eq[USize](1, workspaces.size())
let workspace = workspaces(0)?
h.assert_eq[USize](2, workspaces.size())
// main.pony workspace has been found first
var workspace = workspaces(0)?
h.assert_eq[String](folder.path, workspace.folder.path)

// corral workspace
workspace = workspaces(1)?
h.assert_eq[String](folder.join("workspace")?.path, workspace.folder.path)

let router = WorkspaceRouter.create()
let compiler = PonyCompiler("") // dummy, not actually in use

Expand Down
27 changes: 23 additions & 4 deletions lsp/workspace/scanner.pony
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use ".."
use "assert"
use "collections"
use "files"
use "itertools"
use "immutable-json"

class WorkspaceScanner
Expand All @@ -10,14 +11,14 @@ class WorkspaceScanner
new val create(channel: Channel) =>
_channel = channel

fun _scan_dir(
fun _scan_corral_dir(
dir: FilePath,
workspace_name: String,
visited: Set[String] ref = Set[String].create()
): WorkspaceData ? =>
visited.set(dir.path)

// load corral.json
// load corral.json if available
let corral_json_path = dir.join("corral.json")?
_channel.log("corral.json @ " + corral_json_path.path)
let corral_json_file = OpenFile(corral_json_path) as File
Expand Down Expand Up @@ -55,7 +56,7 @@ class WorkspaceScanner
// scan for transitive dependencies
// but only if we havent visited before
// to avoid endlees loops over cyclic dependencies
let sub_workspace = this._scan_dir(locator_dir, workspace_name, visited)?
let sub_workspace = this._scan_corral_dir(locator_dir, workspace_name, visited)?
for sub_dependency in sub_workspace.dependencies.values() do
dependencies.set(sub_dependency)
end
Expand All @@ -82,12 +83,30 @@ class WorkspaceScanner
let idx = dir_entries.find("_corral" where predicate = {(a,b) => a == b})?
dir_entries.delete(idx)?
end
// first look for a `corral.json` file
try
dir_entries.find("corral.json" where predicate = {(a,b) => a == b})?
let workspace = that._scan_dir(dir_path, name)?
let workspace = that._scan_corral_dir(dir_path, name)?
_channel.log("Added workspace: " + workspace.debug())
workspaces.push(workspace)
end
// if no `corral.json` could be found, search for a `main.pony`
try
// ensure we are not inside a folder that is alrady in a workspace,
// those are scanned
dir_entries.find("main.pony" where predicate = {(a,b) => a == b})?
try
Iter[WorkspaceData](workspaces.values()).find({(workspace: WorkspaceData) =>
dir_path.path.at(workspace.folder.path, 0)
})?
else
// not inside a known workspace
let main_workspace_name: String = dir_path.path.substring((folder.size() + 1).isize())
workspaces.push(
WorkspaceData(main_workspace_name, dir_path, Set[String].create(0), Set[String].create(0))
)
end
end

end
path.walk(handler)
Expand Down