Skip to content

Commit 7fd7589

Browse files
authored
build: make copy of autocomplete package at package/autocomplete (#497)
1 parent df4904f commit 7fd7589

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+7962
-0
lines changed

packages/autocomplete/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
dist-ssr
3+
.env

packages/autocomplete/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<p align="center">
2+
<img width="300" src="https://github.com/withfig/fig/blob/main/static/FigBanner.png?raw=true"/>
3+
</p>
4+
5+
---
6+
7+
# Autocomplete v9
8+
9+
This is where all the changes to autocomplete are made. This readme will
10+
be updated for each version of autocomplete
11+
12+
## Folders and Files
13+
14+
- `fig/`: Wrappers around the fig.js API to make it nicer to work with
15+
- `parser/`: Parses command line output using a bash parser and then
16+
a contextual parser that incorporates completion specs
17+
- `generators/`: Launches asynchronous requests to generator suggestions
18+
dynamically
19+
- `suggestions/`: Utilities to compute, sort, and filter a list of
20+
suggestions from parser results and generators that have completed
21+
- `state/`: Manages react state including figState
22+
from fig.js hooks, parser results, generator results, suggestions to
23+
display, and visibility of the window
24+
- `hooks/keypress.ts`: Handles keypresses from the user, updating state
25+
accordingly
26+
27+
## How it works
28+
29+
The primary logic for the app is contained within
30+
`state/` and `App.tsx` which synthesize the parts listed
31+
above into the autocomplete app. In particular,
32+
`state/` lays out a reducer that dictates all of the
33+
ways the state of the fig app can change. We want to update state at the
34+
following times:
35+
36+
- We receive an autocomplete event from the fig.js API. We call
37+
`setFigState` to update the current buffer, cwd, etc. in our `autocompleteState`
38+
- The buffer has changed. We must re-parse the new buffer. This is
39+
done asynchronous because of the need to load spec files from disk.
40+
When the parser is complete we call `updateParserResult`.
41+
- A generator has completed. If the results aren't stale, we must update
42+
our generator state with the new results, calling
43+
`updateGeneratorResult`
44+
- We receive a keypress even from the fig.js API. Depending on the
45+
keypress, we might need to update the selected item index, or possibly
46+
hide the autocomplete window. We call `hide` or `scroll` to update state.
47+
- An unrecoverable error occurs. We want to hide the fig window until we
48+
can show something again.
49+
50+
The functions/actions mentioned above are all defined in
51+
`state/`.
52+
53+
Every time we update the state in one of the ways mentioned above, we
54+
might need to get a new list of suggestions. We also might need to trigger
55+
generators if the search term that the user typed for the current argument
56+
has changed. Every time we update state, we do a few checks to see if we
57+
need to regenerate suggestions or trigger generators.
58+
59+
## Versioning
60+
61+
New versions of autocomplete are created when changes are made to the
62+
autocomplete spec format. For example, if we add “generators” as
63+
a property of args, this is a change. AND changes to the fig hooks that
64+
are sent
65+
66+
## Testing locally
67+
68+
You can launch the autocomplete engine locally by running:
69+
70+
```bash
71+
npm run dev
72+
```
73+
74+
which will start serving the repo with hot reloading on `localhost:3000`
75+
76+
**Tip**: to view logs in the console when their source is displaying instrument.ts, right click anywhere it says "instrument.ts" and click "Blackbox Script" in the option menu

packages/autocomplete/dev.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
trap 'yarn remove-host' SIGINT; { sleep 0.5 && yarn set-host; } & vite --port 3124
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @ts-check
2+
import react from "@amzn/eslint-config/react";
3+
export default react({
4+
tsconfigPath: "./tsconfig.json",
5+
});

packages/autocomplete/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Q Autocomplete</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>

packages/autocomplete/package.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "@amzn/autocomplete",
3+
"private": true,
4+
"version": "1.0.0",
5+
"repository": "https://github.com/aws/amazon-q-developer-cli",
6+
"type": "module",
7+
"scripts": {
8+
"set-host": "fig settings developer.autocomplete.host http://localhost:3124",
9+
"remove-host": "fig settings developer.autocomplete.host --delete",
10+
"dev": "vite",
11+
"build": "tsc && vite build",
12+
"preview": "vite preview",
13+
"serve": "vite preview --port 3124",
14+
"test": "vitest",
15+
"lint": "eslint src --report-unused-disable-directives && prettier --check src",
16+
"lint:fix": "eslint src --fix && prettier --write src",
17+
"clean": "rm -rf dist"
18+
},
19+
"browserslist": [
20+
"defaults",
21+
"Safari >= 11"
22+
],
23+
"dependencies": {
24+
"@aws/amazon-q-developer-cli-api-bindings-wrappers": "workspace:^",
25+
"@aws/amazon-q-developer-cli-api-bindings": "workspace:~",
26+
"@aws/amazon-q-developer-cli-autocomplete-parser": "workspace:^",
27+
"@aws/amazon-q-developer-cli-proto": "workspace:^",
28+
"@aws/amazon-q-developer-cli-shell-parser": "workspace:^",
29+
"@bufbuild/protobuf": "2.2.3",
30+
"@fig/autocomplete-helpers": "^2.0.0",
31+
"@fig/autocomplete-shared": "^1.1.2",
32+
"@juggle/resize-observer": "^3.4.0",
33+
"deep-object-diff": "^1.1.9",
34+
"loglevel": "^1.9.2",
35+
"react-dom": "^18.3.1",
36+
"react-window": "^1.8.11",
37+
"react": "^18.3.1",
38+
"tailwind-merge": "^2.6.0",
39+
"use-resize-observer": "^9.1.0",
40+
"util": "^0.12.5",
41+
"zustand": "^4.5.6"
42+
},
43+
"devDependencies": {
44+
"@amzn/eslint-config": "workspace:^",
45+
"@amzn/types": "workspace:^",
46+
"@aws/amazon-q-developer-cli-fuzzysort": "workspace:^",
47+
"@aws/amazon-q-developer-cli-shared": "workspace:^",
48+
"@types/js-yaml": "^4.0.9",
49+
"@types/node": "^22.10.6",
50+
"@types/react-dom": "^18.3.5",
51+
"@types/react-window": "^1.8.8",
52+
"@types/react": "^18.3.18",
53+
"@types/semver": "^7.5.8",
54+
"@vitejs/plugin-legacy": "^6.0.0",
55+
"@vitejs/plugin-react": "^4.3.4",
56+
"@withfig/autocomplete-types": "^1.31.0",
57+
"autoprefixer": "^10.4.20",
58+
"eslint": "^9.18.0",
59+
"postcss": "^8.5.1",
60+
"prettier": "^3.4.2",
61+
"tailwindcss": "^3.4.17",
62+
"terser": "^5.37.0",
63+
"typescript": "^5.7.3",
64+
"vite": "^6.0.7",
65+
"vitest": "^2.1.8"
66+
},
67+
"bundledDependencies": [
68+
"@aws/amazon-q-developer-cli-fuzzysort",
69+
"@aws/amazon-q-developer-cli-shared"
70+
]
71+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
};

0 commit comments

Comments
 (0)