дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
feat(editor): complete paths on bare lines in ignore files (#6007)
Path completion only triggered inside quoted strings, HTML attributes, url() and Markdown links, so it never fired in .gitignore-style files. Each non-comment line of an ignore file (.gitignore, .dockerignore, ...) is now a path prefix completed eagerly from the file system, after an optional `!`. Glob patterns and comment lines are left alone. Co-authored-by: muutot <[email protected]>
Цей коміт міститься в:
1 джерело
cb6b7ccd3f
коміт
df48d9271b
2 files changed
+19
No files matched your search
@@ -10,6 +10,17 @@ describe("path completion context", () => {
|
||||
expect(pathContext("See [docs](guide/", "markdown")).toEqual({ prefix: "guide/", eager: true });
|
||||
});
|
||||
|
||||
it("completes bare path lines in ignore files", () => {
|
||||
expect(pathContext("target/", "ignore")).toEqual({ prefix: "target/", eager: true });
|
||||
expect(pathContext("src/comp", "ignore")).toEqual({ prefix: "src/comp", eager: true });
|
||||
expect(pathContext("node_modules", "ignore")).toEqual({ prefix: "node_modules", eager: true });
|
||||
expect(pathContext("!node_modules", "ignore")).toEqual({ prefix: "node_modules", eager: true });
|
||||
expect(pathContext("/src-tauri/gen", "ignore")).toEqual({ prefix: "/src-tauri/gen", eager: true });
|
||||
expect(pathContext(" # a comment", "ignore")).toBeNull();
|
||||
expect(pathContext("*.log", "ignore")).toBeNull();
|
||||
expect(pathContext("src/*.ts", "ignore")).toBeNull();
|
||||
});
|
||||
|
||||
it("completes string literals only once they look like paths", () => {
|
||||
expect(pathContext('open("data/x', "python")).toEqual({ prefix: "data/x", eager: false });
|
||||
expect(pathLike("data/x") && pathLike("./") && pathLike("../a")).toBe(true);
|
||||
|
||||
@@ -44,6 +44,14 @@ export const pathLike = (prefix: string) => /^\.{1,2}\/|\//.test(prefix);
|
||||
|
||||
/** The path being typed at the end of `before` (the line up to the caret), if any. */
|
||||
export function pathContext(before: string, language: string): PathContext | null {
|
||||
if (language === "ignore") {
|
||||
// Every non-comment line in a .gitignore-style file is a path pattern:
|
||||
// complete it eagerly, but leave glob patterns to the user.
|
||||
if (/^\s*#/.test(before)) return null;
|
||||
const prefix = before.replace(/^\s*!?\s*/, "");
|
||||
if (/[*?[\]]/.test(prefix)) return null;
|
||||
return { prefix, eager: true };
|
||||
}
|
||||
for (const re of [URL_ATTRIBUTE, CSS_URL, CSS_IMPORT, MARKDOWN_LINK]) {
|
||||
const m = re.exec(before);
|
||||
if (m) return { prefix: m[1]!, eager: true };
|
||||
|
||||
Reference in new issue
Заблокувати користувача