From 999cb24ab1b8868cdf2cd38766483373268ec67c Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 3 Jun 2025 10:02:36 +0200 Subject: [PATCH 1/8] Updated contributor docs wit info about adding language.mdx --- .../src/docs/contributing/adding-a-new-language.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-language.md b/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-language.md index 8a1d5f5bd6..c1a18a917f 100644 --- a/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-language.md +++ b/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-language.md @@ -38,3 +38,15 @@ You can file a PR with just these changes to get the ball rolling. ## 4. Define your language's scopes Follow the instructions in [Adding a new scope](./adding-a-new-scope.md) to define the scopes for your language. Note that you can file a PR for each added scope, or do a couple at a time, but it's best _**not**_ to do them all at once, as smaller PRs make the review process easier. + +## 5. Document your language + +Create a `.mdx` file in [`languages`](../user/languages) with the `Language` react component. The file should be named after your language, eg `java.mdx` + +```md +import { Language } from "./components/Language"; + +# Java + + +``` From a2392773d8ec775c685c0d8d9aeb98da93909746 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 3 Jun 2025 10:09:27 +0200 Subject: [PATCH 2/8] Update link --- .../src/docs/contributing/adding-a-new-language.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-language.md b/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-language.md index c1a18a917f..2b83dae394 100644 --- a/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-language.md +++ b/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-language.md @@ -41,7 +41,7 @@ Follow the instructions in [Adding a new scope](./adding-a-new-scope.md) to defi ## 5. Document your language -Create a `.mdx` file in [`languages`](../user/languages) with the `Language` react component. The file should be named after your language, eg `java.mdx` +Create a `.mdx` file in [`languages`](../../user/languages) with the `Language` react component. The file should be named after your language, eg `java.mdx` ```md import { Language } from "./components/Language"; From cf429de69aedd7ab15923409391cf89e4699c782 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 3 Jun 2025 10:46:58 +0200 Subject: [PATCH 3/8] Update how links are resolved --- .../cursorless-org-docs/docusaurus.config.mts | 15 +++++++++++++-- .../docs/contributing/adding-a-new-language.md | 2 +- .../architecture/neovim-test-infrastructure.md | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/cursorless-org-docs/docusaurus.config.mts b/packages/cursorless-org-docs/docusaurus.config.mts index 69e2b42c53..8388d03ae5 100644 --- a/packages/cursorless-org-docs/docusaurus.config.mts +++ b/packages/cursorless-org-docs/docusaurus.config.mts @@ -9,6 +9,10 @@ import { fileURLToPath } from "node:url"; const require = createRequire(import.meta.url); +const userRelative = "packages/cursorless-org-docs/src/docs/user"; +const contributingRelative = + "packages/cursorless-org-docs/src/docs/contributing"; + /** * Files within /docs reference repository directories * and files outside of that folder. They are not served @@ -41,12 +45,19 @@ function remarkPluginFixLinksToRepositoryArtifacts(): Transformer { dirname(fileURLToPath(import.meta.url)), "../..", ); + const artifact = resolve(file.dirname!, url); const artifactRelative = relative(repoRoot, artifact).replace(/\\/g, "/"); + const fileRelative = relative(repoRoot, file.path).replace(/\\/g, "/"); - // We host all files under docs, will resolve as a relative link + // We host all files under docs, will resolve as a relative link, but + // relative links passing between user and contributing are not resolved + // correctly if ( - artifactRelative.startsWith("packages/cursorless-org-docs/src/docs/") + (artifactRelative.startsWith(userRelative) && + fileRelative.startsWith(userRelative)) || + (artifactRelative.startsWith(contributingRelative) && + fileRelative.startsWith(contributingRelative)) ) { return; } diff --git a/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-language.md b/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-language.md index 2b83dae394..c1a18a917f 100644 --- a/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-language.md +++ b/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-language.md @@ -41,7 +41,7 @@ Follow the instructions in [Adding a new scope](./adding-a-new-scope.md) to defi ## 5. Document your language -Create a `.mdx` file in [`languages`](../../user/languages) with the `Language` react component. The file should be named after your language, eg `java.mdx` +Create a `.mdx` file in [`languages`](../user/languages) with the `Language` react component. The file should be named after your language, eg `java.mdx` ```md import { Language } from "./components/Language"; diff --git a/packages/cursorless-org-docs/src/docs/contributing/architecture/neovim-test-infrastructure.md b/packages/cursorless-org-docs/src/docs/contributing/architecture/neovim-test-infrastructure.md index 7fe04eaf10..213e54cf56 100644 --- a/packages/cursorless-org-docs/src/docs/contributing/architecture/neovim-test-infrastructure.md +++ b/packages/cursorless-org-docs/src/docs/contributing/architecture/neovim-test-infrastructure.md @@ -300,7 +300,7 @@ cursorless.nvim/.busted ### Running lua unit tests Many of the cursorless.nvim lua functions are run in order to complete Cursorless actions and so are already -indirectly tested by the tests described in the [previous section](#3-cursorless-tests-for-neovim). Nevertheless, we run +indirectly tested by the tests described in the [previous section](#running-neovim-tests-locally). Nevertheless, we run more specific unit tests in order to give better visibility into exactly which functions are failing. The [busted](https://github.com/lunarmodules/busted) framework is used to test lua functions defined in cursorless.nvim. This relies on a `cursorless.nvim/.busted` file which directs busted to use a lua interpreter and test specifications files: From c75c737253fb001372810f2648cc6184d0072604 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 3 Jun 2025 10:48:20 +0200 Subject: [PATCH 4/8] Cleanup --- packages/cursorless-org-docs/docusaurus.config.mts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/cursorless-org-docs/docusaurus.config.mts b/packages/cursorless-org-docs/docusaurus.config.mts index 8388d03ae5..5ce35fb4bd 100644 --- a/packages/cursorless-org-docs/docusaurus.config.mts +++ b/packages/cursorless-org-docs/docusaurus.config.mts @@ -12,6 +12,7 @@ const require = createRequire(import.meta.url); const userRelative = "packages/cursorless-org-docs/src/docs/user"; const contributingRelative = "packages/cursorless-org-docs/src/docs/contributing"; +const repoLink = "https://github.com/cursorless-dev/cursorless/tree/main/"; /** * Files within /docs reference repository directories @@ -62,11 +63,7 @@ function remarkPluginFixLinksToRepositoryArtifacts(): Transformer { return; } - const repoLink = - "https://github.com/cursorless-dev/cursorless/tree/main/"; - const linkToRepositoryArtifact = repoLink.concat(artifactRelative); - - node.url = linkToRepositoryArtifact; + node.url = repoLink.concat(artifactRelative); }); }; } From 751d168eadb29006928dcd3c359097b2f93a0e08 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 3 Jun 2025 10:51:42 +0200 Subject: [PATCH 5/8] Elaborate on comment --- packages/cursorless-org-docs/docusaurus.config.mts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/cursorless-org-docs/docusaurus.config.mts b/packages/cursorless-org-docs/docusaurus.config.mts index 5ce35fb4bd..fc0afe8bce 100644 --- a/packages/cursorless-org-docs/docusaurus.config.mts +++ b/packages/cursorless-org-docs/docusaurus.config.mts @@ -46,14 +46,13 @@ function remarkPluginFixLinksToRepositoryArtifacts(): Transformer { dirname(fileURLToPath(import.meta.url)), "../..", ); - const artifact = resolve(file.dirname!, url); const artifactRelative = relative(repoRoot, artifact).replace(/\\/g, "/"); const fileRelative = relative(repoRoot, file.path).replace(/\\/g, "/"); // We host all files under docs, will resolve as a relative link, but // relative links passing between user and contributing are not resolved - // correctly + // correctly by docusaurus, so we need to rewrite them. if ( (artifactRelative.startsWith(userRelative) && fileRelative.startsWith(userRelative)) || @@ -63,7 +62,7 @@ function remarkPluginFixLinksToRepositoryArtifacts(): Transformer { return; } - node.url = repoLink.concat(artifactRelative); + node.url = repoLink + artifactRelative; }); }; } From 548314ffaa90ccc80ef47a9247736547f8cbb700 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 3 Jun 2025 10:53:25 +0200 Subject: [PATCH 6/8] Clean up --- packages/cursorless-org-docs/docusaurus.config.mts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cursorless-org-docs/docusaurus.config.mts b/packages/cursorless-org-docs/docusaurus.config.mts index fc0afe8bce..f72bf66ff5 100644 --- a/packages/cursorless-org-docs/docusaurus.config.mts +++ b/packages/cursorless-org-docs/docusaurus.config.mts @@ -50,9 +50,9 @@ function remarkPluginFixLinksToRepositoryArtifacts(): Transformer { const artifactRelative = relative(repoRoot, artifact).replace(/\\/g, "/"); const fileRelative = relative(repoRoot, file.path).replace(/\\/g, "/"); - // We host all files under docs, will resolve as a relative link, but + // We host all files under docs. Will resolve as a relative link, but // relative links passing between user and contributing are not resolved - // correctly by docusaurus, so we need to rewrite them. + // correctly by docusaurus. So we need to rewrite them. if ( (artifactRelative.startsWith(userRelative) && fileRelative.startsWith(userRelative)) || From adefd5735089ff343036f89ca544924b5bf30e60 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 3 Jun 2025 11:04:28 +0200 Subject: [PATCH 7/8] Throw unbroken anchors --- packages/cursorless-org-docs/docusaurus.config.mts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cursorless-org-docs/docusaurus.config.mts b/packages/cursorless-org-docs/docusaurus.config.mts index f72bf66ff5..61865b4d9d 100644 --- a/packages/cursorless-org-docs/docusaurus.config.mts +++ b/packages/cursorless-org-docs/docusaurus.config.mts @@ -106,6 +106,7 @@ const config: Config = { ], onBrokenLinks: "throw", onBrokenMarkdownLinks: "throw", + onBrokenAnchors: "throw", trailingSlash: true, presets: [ From 906a49eda3731b0b0be95075a75a3f017dba1cac Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 3 Jun 2025 12:01:07 +0200 Subject: [PATCH 8/8] Only rewrite folders --- .../cursorless-org-docs/docusaurus.config.mts | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/packages/cursorless-org-docs/docusaurus.config.mts b/packages/cursorless-org-docs/docusaurus.config.mts index 61865b4d9d..e332156b88 100644 --- a/packages/cursorless-org-docs/docusaurus.config.mts +++ b/packages/cursorless-org-docs/docusaurus.config.mts @@ -1,17 +1,17 @@ import type { Config } from "@docusaurus/types"; import type { Root } from "mdast"; -import { dirname, relative, resolve } from "path"; +import { createRequire } from "node:module"; +import { fileURLToPath } from "node:url"; +import { dirname, extname, relative, resolve } from "path"; import { themes } from "prism-react-renderer"; import type { Transformer } from "unified"; import { visit } from "unist-util-visit"; -import { createRequire } from "node:module"; -import { fileURLToPath } from "node:url"; const require = createRequire(import.meta.url); -const userRelative = "packages/cursorless-org-docs/src/docs/user"; -const contributingRelative = - "packages/cursorless-org-docs/src/docs/contributing"; +const docsRelative = "packages/cursorless-org-docs/src/docs/"; +const userRelative = docsRelative + "user"; +const contributingRelative = docsRelative + "contributing"; const repoLink = "https://github.com/cursorless-dev/cursorless/tree/main/"; /** @@ -51,14 +51,16 @@ function remarkPluginFixLinksToRepositoryArtifacts(): Transformer { const fileRelative = relative(repoRoot, file.path).replace(/\\/g, "/"); // We host all files under docs. Will resolve as a relative link, but - // relative links passing between user and contributing are not resolved - // correctly by docusaurus. So we need to rewrite them. - if ( - (artifactRelative.startsWith(userRelative) && - fileRelative.startsWith(userRelative)) || - (artifactRelative.startsWith(contributingRelative) && - fileRelative.startsWith(contributingRelative)) - ) { + // relative links pointing to a folder passing between user and + // contributing are not resolved correctly by docusaurus so we need to + // rewrite them. + if (artifactRelative.startsWith(docsRelative)) { + if ( + isFolder(url) && + passingBetweenUserAndContributing(fileRelative, artifactRelative) + ) { + node.url = "/docs/" + artifactRelative.slice(docsRelative.length); + } return; } @@ -67,6 +69,19 @@ function remarkPluginFixLinksToRepositoryArtifacts(): Transformer { }; } +function isFolder(url: string) { + return !extname(url); +} + +function passingBetweenUserAndContributing( + fileRelative: string, + artifactRelative: string, +): boolean { + return fileRelative.startsWith(userRelative) + ? !artifactRelative.startsWith(userRelative) + : !artifactRelative.startsWith(contributingRelative); +} + const config: Config = { title: "Cursorless", tagline: "Structural voice coding at the speed of thought",