Skip to content

Commit 99e5dff

Browse files
committed
[forgive] Init
Init basic LSP. At the moment the extension doesn't do anything interesting, but it does compile successfully.
1 parent 85818f0 commit 99e5dff

File tree

17 files changed

+1271
-49
lines changed

17 files changed

+1271
-49
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ packages/react-devtools-fusebox/dist
3737
packages/react-devtools-inline/dist
3838
packages/react-devtools-shell/dist
3939
packages/react-devtools-timeline/dist
40+

compiler/.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ dist
2121
.spr.yml
2222
testfilter.txt
2323

24-
bundle-oss.sh
24+
bundle-oss.sh
25+
26+
# forgive
27+
*.vsix
28+
.vscode-test
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {defineConfig} from '@vscode/test-cli';
2+
3+
export default defineConfig({files: 'dist/test/**/*.test.js'});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/node_modules
2+
client
3+
server
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignore-engines true
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Meta Platforms, Inc. and affiliates.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

compiler/packages/react-forgive/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"repository": {
1212
"type": "git",
1313
"url": "git+https://github.com/facebook/react.git",
14-
"directory": "compiler/packages/react-forgive-client"
14+
"directory": "compiler/packages/react-forgive"
1515
},
1616
"dependencies": {
1717
"vscode-languageclient": "^9.0.1"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import * as path from 'path';
2+
import {ExtensionContext, window as Window} from 'vscode';
3+
4+
import {
5+
LanguageClient,
6+
LanguageClientOptions,
7+
ServerOptions,
8+
TransportKind,
9+
} from 'vscode-languageclient/node';
10+
11+
let client: LanguageClient;
12+
13+
export function activate(context: ExtensionContext) {
14+
const serverModule = context.asAbsolutePath(path.join('dist', 'server.js'));
15+
16+
// If the extension is launched in debug mode then the debug server options are used
17+
// Otherwise the run options are used
18+
const serverOptions: ServerOptions = {
19+
run: {
20+
module: serverModule,
21+
transport: TransportKind.ipc,
22+
options: {cwd: process.cwd()},
23+
},
24+
debug: {
25+
module: serverModule,
26+
transport: TransportKind.ipc,
27+
options: {cwd: process.cwd()},
28+
},
29+
};
30+
31+
const clientOptions: LanguageClientOptions = {
32+
documentSelector: [
33+
{scheme: 'file', language: 'javascriptreact'},
34+
{scheme: 'file', language: 'typescriptreact'},
35+
],
36+
progressOnInitialization: true,
37+
};
38+
39+
// Create the language client and start the client.
40+
try {
41+
client = new LanguageClient(
42+
'react-forgive',
43+
'React Analyzer',
44+
serverOptions,
45+
clientOptions,
46+
);
47+
} catch {
48+
Window.showErrorMessage(
49+
`React Analyzer couldn't be started. See the output channel for details.`,
50+
);
51+
return;
52+
}
53+
54+
client.registerProposedFeatures();
55+
client.start();
56+
}
57+
58+
export function deactivate(): Thenable<void> | undefined {
59+
if (client !== undefined) {
60+
return client.stop();
61+
}
62+
}

compiler/packages/react-forgive/package.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,30 @@
3535
]
3636
},
3737
"scripts": {
38-
"compile": "yarn run esbuild-base -- --sourcemap",
38+
"build": "yarn run compile",
39+
"compile": "rimraf dist && concurrently -n server,client \"yarn run esbuild:server --sourcemap\" \"yarn run esbuild:client --sourcemap\"",
3940
"dev": "yarn run package && yarn run install-ext",
40-
"esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node",
41-
"install-ext": "code --install-extension vscode-react-compiler-0.0.1.vsix",
42-
"lint": "eslint src --ext ts",
43-
"package": "vsce package",
41+
"esbuild:client": "esbuild ./client/src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node",
42+
"esbuild:server": "esbuild ./server/src/index.ts --bundle --outfile=dist/server.js --external:vscode --format=cjs --platform=node",
43+
"install-ext": "code --install-extension react-forgive-0.0.0.vsix",
44+
"lint": "echo 'no tests'",
45+
"package": "rm -f react-forgive-0.0.0.vsix && vsce package --yarn",
4446
"postinstall": "cd client && yarn install && cd ../server && yarn install && cd ..",
4547
"pretest": "yarn run compile && yarn run lint",
4648
"test": "vscode-test",
47-
"test-compile": "tsc -p ./",
48-
"vscode:prepublish": "yarn run esbuild-base -- --minify",
49-
"watch": "yarn run esbuild-base -- --sourcemap --watch"
49+
"vscode:prepublish": "yarn run compile",
50+
"watch": "concurrently --kill-others -n server,client \"run esbuild:server --sourcemap --watch\" \"run esbuild:client --sourcemap --watch\""
5051
},
5152
"devDependencies": {
5253
"@eslint/js": "^9.13.0",
54+
"@types/mocha": "^10.0.10",
5355
"@types/node": "^20",
56+
"@types/vscode": "^1.96.0",
57+
"@vscode/test-cli": "^0.0.10",
58+
"@vscode/test-electron": "^2.4.1",
5459
"esbuild": "^0.24.0",
5560
"eslint": "^9.13.0",
56-
"typescript": "^5.7.2",
61+
"mocha": "^11.0.1",
5762
"typescript-eslint": "^8.16.0"
5863
}
5964
}

compiler/packages/react-forgive/server/package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@
44
"version": "0.0.0",
55
"description": "Experimental LSP server",
66
"license": "MIT",
7+
"main": "dist/index.js",
78
"scripts": {
8-
"build": "echo 'no build'",
9+
"build": "rimraf dist && rollup --config --bundleConfigAsCjs",
910
"test": "echo 'no tests'"
1011
},
1112
"repository": {
1213
"type": "git",
1314
"url": "git+https://github.com/facebook/react.git",
14-
"directory": "compiler/packages/react-forgive-server"
15+
"directory": "compiler/packages/react-forgive"
1516
},
1617
"dependencies": {
18+
"@babel/core": "^7.26.0",
19+
"@babel/parser": "^7.26.0",
20+
"@babel/plugin-syntax-typescript": "^7.25.9",
21+
"@babel/types": "^7.26.0",
22+
"cosmiconfig": "^9.0.0",
23+
"prettier": "^3.3.3",
1724
"vscode-languageserver": "^9.0.1",
1825
"vscode-languageserver-textdocument": "^1.0.12"
1926
}

0 commit comments

Comments
 (0)