MCPcopy Index your code
hub / github.com/anomalyco/opencode / NearestRoot

Function NearestRoot

packages/opencode/src/lsp/server.ts:32–54  ·  view source on GitHub ↗
(includePatterns: string[], excludePatterns?: string[])

Source from the content-addressed store, hash-verified

30type RootFunction = (file: string, ctx: InstanceContext) => Promise<string | undefined>
31
32const NearestRoot = (includePatterns: string[], excludePatterns?: string[]): RootFunction => {
33 return async (file, ctx) => {
34 if (excludePatterns) {
35 const excludedFiles = Filesystem.up({
36 targets: excludePatterns,
37 start: path.dirname(file),
38 stop: ctx.directory,
39 })
40 const excluded = await excludedFiles.next()
41 await excludedFiles.return()
42 if (excluded.value) return undefined
43 }
44 const files = Filesystem.up({
45 targets: includePatterns,
46 start: path.dirname(file),
47 stop: ctx.directory,
48 })
49 const first = await files.next()
50 await files.return()
51 if (!first.value) return ctx.directory
52 return path.dirname(first.value)
53 }
54}
55
56const StrictNearestRoot = (includePatterns: string[], excludePatterns?: string[]): RootFunction => {
57 return async (file, ctx) => {

Callers 1

server.tsFile · 0.85

Calls 1

nextMethod · 0.45

Tested by

no test coverage detected