refactor(core): drop filesystem entry mime
This commit is contained in:
parent
53076999c5
commit
e8610d821c
@ -111,7 +111,6 @@ const baseLayer = Layer.effect(
|
|||||||
new Entry({
|
new Entry({
|
||||||
path: RelativePath.make(relative + (item.type === "directory" ? path.sep : "")),
|
path: RelativePath.make(relative + (item.type === "directory" ? path.sep : "")),
|
||||||
type: item.type,
|
type: item.type,
|
||||||
mime: item.type === "directory" ? "application/x-directory" : FSUtil.mimeType(absolute),
|
|
||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import { NonNegativeInt, PositiveInt, RelativePath } from "../schema"
|
|||||||
export class Entry extends Schema.Class<Entry>("FileSystem.Entry")({
|
export class Entry extends Schema.Class<Entry>("FileSystem.Entry")({
|
||||||
path: RelativePath,
|
path: RelativePath,
|
||||||
type: Schema.Literals(["file", "directory"]),
|
type: Schema.Literals(["file", "directory"]),
|
||||||
mime: Schema.String,
|
|
||||||
}) {}
|
}) {}
|
||||||
|
|
||||||
export const Submatch = Schema.Struct({
|
export const Submatch = Schema.Struct({
|
||||||
|
|||||||
@ -110,12 +110,9 @@ export const ripgrepLayer = Layer.effect(
|
|||||||
return fuzzysort.go(input.query, items, { limit: input.limit ?? 50 }).map((item) => {
|
return fuzzysort.go(input.query, items, { limit: input.limit ?? 50 }).map((item) => {
|
||||||
const relative = item.target
|
const relative = item.target
|
||||||
const type = relative.endsWith(path.sep) ? ("directory" as const) : ("file" as const)
|
const type = relative.endsWith(path.sep) ? ("directory" as const) : ("file" as const)
|
||||||
const clean = type === "directory" ? relative.slice(0, -path.sep.length) : relative
|
|
||||||
const absolute = path.resolve(location.directory, clean)
|
|
||||||
return new FileSystem.Entry({
|
return new FileSystem.Entry({
|
||||||
path: RelativePath.make(relative),
|
path: RelativePath.make(relative),
|
||||||
type,
|
type,
|
||||||
mime: type === "directory" ? "application/x-directory" : FSUtil.mimeType(absolute),
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
@ -148,14 +145,13 @@ export const fffLayer = Layer.effect(
|
|||||||
pageSize: input.limit,
|
pageSize: input.limit,
|
||||||
})
|
})
|
||||||
if (!found.ok) throw found.error
|
if (!found.ok) throw found.error
|
||||||
return found.value.items.map((item) => {
|
return found.value.items.map(
|
||||||
const absolute = path.resolve(location.directory, item.relativePath)
|
(item) =>
|
||||||
return new FileSystem.Entry({
|
new FileSystem.Entry({
|
||||||
path: RelativePath.make(item.relativePath.replaceAll("\\", "/")),
|
path: RelativePath.make(item.relativePath.replaceAll("\\", "/")),
|
||||||
type: "file",
|
type: "file",
|
||||||
mime: FSUtil.mimeType(absolute),
|
}),
|
||||||
})
|
)
|
||||||
})
|
|
||||||
}),
|
}),
|
||||||
grep: (input) =>
|
grep: (input) =>
|
||||||
Effect.sync(() => {
|
Effect.sync(() => {
|
||||||
@ -173,7 +169,6 @@ export const fffLayer = Layer.effect(
|
|||||||
entry: new FileSystem.Entry({
|
entry: new FileSystem.Entry({
|
||||||
path: RelativePath.make(match.relativePath.replaceAll("\\", "/")),
|
path: RelativePath.make(match.relativePath.replaceAll("\\", "/")),
|
||||||
type: "file",
|
type: "file",
|
||||||
mime: FSUtil.mimeType(match.relativePath),
|
|
||||||
}),
|
}),
|
||||||
line: match.lineNumber,
|
line: match.lineNumber,
|
||||||
offset: match.byteOffset,
|
offset: match.byteOffset,
|
||||||
@ -220,11 +215,9 @@ export const fffLayer = Layer.effect(
|
|||||||
.sort((a, b) => b.score - a.score || a.path.length - b.path.length)
|
.sort((a, b) => b.score - a.score || a.path.length - b.path.length)
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
const relative = item.path.replaceAll("\\", "/").replace(/\/$/, "")
|
const relative = item.path.replaceAll("\\", "/").replace(/\/$/, "")
|
||||||
const absolute = path.resolve(location.directory, relative)
|
|
||||||
return new FileSystem.Entry({
|
return new FileSystem.Entry({
|
||||||
path: RelativePath.make(relative + (item.type === "directory" ? path.sep : "")),
|
path: RelativePath.make(relative + (item.type === "directory" ? path.sep : "")),
|
||||||
type: item.type,
|
type: item.type,
|
||||||
mime: item.type === "directory" ? "application/x-directory" : FSUtil.mimeType(absolute),
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import { ChildProcess } from "effect/unstable/process"
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import { LayerNode } from "./effect/layer-node"
|
import { LayerNode } from "./effect/layer-node"
|
||||||
import { Entry, Match } from "./filesystem/schema"
|
import { Entry, Match } from "./filesystem/schema"
|
||||||
import { FSUtil } from "./fs-util"
|
|
||||||
import { AppProcess, collectStream, waitForAbort } from "./process"
|
import { AppProcess, collectStream, waitForAbort } from "./process"
|
||||||
import { NonNegativeInt, PositiveInt, RelativePath } from "./schema"
|
import { NonNegativeInt, PositiveInt, RelativePath } from "./schema"
|
||||||
import { RipgrepBinary } from "./ripgrep/binary"
|
import { RipgrepBinary } from "./ripgrep/binary"
|
||||||
@ -177,15 +176,14 @@ export const layer = Layer.effect(
|
|||||||
),
|
),
|
||||||
}).pipe(
|
}).pipe(
|
||||||
Effect.map((result) =>
|
Effect.map((result) =>
|
||||||
result.items.map((relative) => {
|
result.items.map(
|
||||||
const absolute = path.resolve(input.cwd, relative)
|
(relative) =>
|
||||||
return new Entry({
|
new Entry({
|
||||||
path: RelativePath.make(relative),
|
path: RelativePath.make(relative),
|
||||||
type: "file",
|
type: "file",
|
||||||
mime: FSUtil.mimeType(absolute),
|
|
||||||
})
|
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
Effect.catchTag("Ripgrep.InvalidPatternError", (cause) => Effect.fail(failure(cause.message, cause))),
|
Effect.catchTag("Ripgrep.InvalidPatternError", (cause) => Effect.fail(failure(cause.message, cause))),
|
||||||
),
|
),
|
||||||
find: (input) =>
|
find: (input) =>
|
||||||
@ -211,7 +209,6 @@ export const layer = Layer.effect(
|
|||||||
new Entry({
|
new Entry({
|
||||||
path: RelativePath.make(relative),
|
path: RelativePath.make(relative),
|
||||||
type: "file",
|
type: "file",
|
||||||
mime: FSUtil.mimeType(path.resolve(input.cwd, relative)),
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -262,12 +259,10 @@ export const layer = Layer.effect(
|
|||||||
.replace(/^(?:\.[\\/])+/u, "")
|
.replace(/^(?:\.[\\/])+/u, "")
|
||||||
.replace(/^[\\/]+/u, "")
|
.replace(/^[\\/]+/u, "")
|
||||||
.replaceAll("\\", "/")
|
.replaceAll("\\", "/")
|
||||||
const absolute = path.resolve(input.cwd, relative)
|
|
||||||
return new Match({
|
return new Match({
|
||||||
entry: new Entry({
|
entry: new Entry({
|
||||||
path: RelativePath.make(relative),
|
path: RelativePath.make(relative),
|
||||||
type: "file",
|
type: "file",
|
||||||
mime: FSUtil.mimeType(absolute),
|
|
||||||
}),
|
}),
|
||||||
line: match.line_number,
|
line: match.line_number,
|
||||||
offset: match.absolute_offset,
|
offset: match.absolute_offset,
|
||||||
|
|||||||
@ -338,7 +338,6 @@ export const list = Effect.fn("ReadTool.list")(function* (fs: FSUtil.Interface,
|
|||||||
return new FileSystem.Entry({
|
return new FileSystem.Entry({
|
||||||
path: RelativePath.make(item.name + (type === "directory" ? path.sep : "")),
|
path: RelativePath.make(item.name + (type === "directory" ? path.sep : "")),
|
||||||
type,
|
type,
|
||||||
mime: type === "directory" ? "application/x-directory" : FSUtil.mimeType(target),
|
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
{ concurrency: 16 },
|
{ concurrency: 16 },
|
||||||
|
|||||||
@ -4207,7 +4207,6 @@ export type PermissionSavedInfo = {
|
|||||||
export type FileSystemEntry = {
|
export type FileSystemEntry = {
|
||||||
path: string
|
path: string
|
||||||
type: "file" | "directory"
|
type: "file" | "directory"
|
||||||
mime: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CommandV2Info = {
|
export type CommandV2Info = {
|
||||||
|
|||||||
@ -27726,12 +27726,9 @@
|
|||||||
"type": {
|
"type": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["file", "directory"]
|
"enum": ["file", "directory"]
|
||||||
},
|
|
||||||
"mime": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["path", "type", "mime"],
|
"required": ["path", "type"],
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
},
|
},
|
||||||
"CommandV2Info": {
|
"CommandV2Info": {
|
||||||
|
|||||||
@ -305,11 +305,7 @@ export function Autocomplete(props: {
|
|||||||
startLine: input.lineStart,
|
startLine: input.lineStart,
|
||||||
endLine: input.lineEnd > input.lineStart ? input.lineEnd : undefined,
|
endLine: input.lineEnd > input.lineStart ? input.lineEnd : undefined,
|
||||||
}
|
}
|
||||||
const { filename, part } = createFilePart(
|
const { filename, part } = createFilePart({ path: item, type: "file" }, input.filePath, lineRange)
|
||||||
{ path: item, type: "file", mime: "text/plain" },
|
|
||||||
input.filePath,
|
|
||||||
lineRange,
|
|
||||||
)
|
|
||||||
const index = store.visible === "@" ? store.index : props.input().cursorOffset
|
const index = store.visible === "@" ? store.index : props.input().cursorOffset
|
||||||
|
|
||||||
setStore("visible", false)
|
setStore("visible", false)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user