Skip to content

Commit 4993046

Browse files
Updated contributor docs with info about adding language.mdx (#2955)
1 parent 175b3f3 commit 4993046

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

packages/cursorless-org-docs/docusaurus.config.mts

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import type { Config } from "@docusaurus/types";
22
import type { Root } from "mdast";
3-
import { dirname, relative, resolve } from "path";
3+
import { createRequire } from "node:module";
4+
import { fileURLToPath } from "node:url";
5+
import { dirname, extname, relative, resolve } from "path";
46
import { themes } from "prism-react-renderer";
57
import type { Transformer } from "unified";
68
import { visit } from "unist-util-visit";
7-
import { createRequire } from "node:module";
8-
import { fileURLToPath } from "node:url";
99

1010
const require = createRequire(import.meta.url);
1111

12+
const docsRelative = "packages/cursorless-org-docs/src/docs/";
13+
const userRelative = docsRelative + "user";
14+
const contributingRelative = docsRelative + "contributing";
15+
const repoLink = "https://github.com/cursorless-dev/cursorless/tree/main/";
16+
1217
/**
1318
* Files within /docs reference repository directories
1419
* and files outside of that folder. They are not served
@@ -43,23 +48,40 @@ function remarkPluginFixLinksToRepositoryArtifacts(): Transformer<Root> {
4348
);
4449
const artifact = resolve(file.dirname!, url);
4550
const artifactRelative = relative(repoRoot, artifact).replace(/\\/g, "/");
51+
const fileRelative = relative(repoRoot, file.path).replace(/\\/g, "/");
4652

47-
// We host all files under docs, will resolve as a relative link
48-
if (
49-
artifactRelative.startsWith("packages/cursorless-org-docs/src/docs/")
50-
) {
53+
// We host all files under docs. Will resolve as a relative link, but
54+
// relative links pointing to a folder passing between user and
55+
// contributing are not resolved correctly by docusaurus so we need to
56+
// rewrite them.
57+
if (artifactRelative.startsWith(docsRelative)) {
58+
if (
59+
isFolder(url) &&
60+
passingBetweenUserAndContributing(fileRelative, artifactRelative)
61+
) {
62+
node.url = "/docs/" + artifactRelative.slice(docsRelative.length);
63+
}
5164
return;
5265
}
5366

54-
const repoLink =
55-
"https://github.com/cursorless-dev/cursorless/tree/main/";
56-
const linkToRepositoryArtifact = repoLink.concat(artifactRelative);
57-
58-
node.url = linkToRepositoryArtifact;
67+
node.url = repoLink + artifactRelative;
5968
});
6069
};
6170
}
6271

72+
function isFolder(url: string) {
73+
return !extname(url);
74+
}
75+
76+
function passingBetweenUserAndContributing(
77+
fileRelative: string,
78+
artifactRelative: string,
79+
): boolean {
80+
return fileRelative.startsWith(userRelative)
81+
? !artifactRelative.startsWith(userRelative)
82+
: !artifactRelative.startsWith(contributingRelative);
83+
}
84+
6385
const config: Config = {
6486
title: "Cursorless",
6587
tagline: "Structural voice coding at the speed of thought",
@@ -99,6 +121,7 @@ const config: Config = {
99121
],
100122
onBrokenLinks: "throw",
101123
onBrokenMarkdownLinks: "throw",
124+
onBrokenAnchors: "throw",
102125
trailingSlash: true,
103126

104127
presets: [

packages/cursorless-org-docs/src/docs/contributing/adding-a-new-language.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,15 @@ You can file a PR with just these changes to get the ball rolling.
3838
## 4. Define your language's scopes
3939

4040
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.
41+
42+
## 5. Document your language
43+
44+
Create a `.mdx` file in [`languages`](../user/languages) with the `Language` react component. The file should be named after your language, eg `java.mdx`
45+
46+
```md
47+
import { Language } from "./components/Language";
48+
49+
# Java
50+
51+
<Language languageId="java"></Language>
52+
```

packages/cursorless-org-docs/src/docs/contributing/architecture/neovim-test-infrastructure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ cursorless.nvim/.busted
300300
### Running lua unit tests
301301
302302
Many of the cursorless.nvim lua functions are run in order to complete Cursorless actions and so are already
303-
indirectly tested by the tests described in the [previous section](#3-cursorless-tests-for-neovim). Nevertheless, we run
303+
indirectly tested by the tests described in the [previous section](#running-neovim-tests-locally). Nevertheless, we run
304304
more specific unit tests in order to give better visibility into exactly which functions are failing.
305305
The [busted](https://github.com/lunarmodules/busted) framework is used to test lua functions defined in cursorless.nvim.
306306
This relies on a `cursorless.nvim/.busted` file which directs busted to use a lua interpreter and test specifications files:

0 commit comments

Comments
 (0)