Skip to content

Commit d42a90c

Browse files
authored
[forgive] Init (#31918)
Init basic LSP. At the moment the extension doesn't do anything interesting, but it does compile successfully.
1 parent 58def9f commit d42a90c

File tree

16 files changed

+1184
-199
lines changed

16 files changed

+1184
-199
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: 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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
},
23+
debug: {
24+
module: serverModule,
25+
transport: TransportKind.ipc,
26+
},
27+
};
28+
29+
const clientOptions: LanguageClientOptions = {
30+
documentSelector: [
31+
{scheme: 'file', language: 'javascriptreact'},
32+
{scheme: 'file', language: 'typescriptreact'},
33+
],
34+
progressOnInitialization: true,
35+
};
36+
37+
// Create the language client and start the client.
38+
try {
39+
client = new LanguageClient(
40+
'react-forgive',
41+
'React Analyzer',
42+
serverOptions,
43+
clientOptions,
44+
);
45+
} catch {
46+
Window.showErrorMessage(
47+
`React Analyzer couldn't be started. See the output channel for details.`,
48+
);
49+
return;
50+
}
51+
52+
client.registerProposedFeatures();
53+
client.start();
54+
}
55+
56+
export function deactivate(): Thenable<void> | undefined {
57+
if (client !== undefined) {
58+
return client.stop();
59+
}
60+
}

compiler/packages/react-forgive/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"publisher": "Meta",
2121
"engines": {
22-
"vscode": "^1.75.0"
22+
"vscode": "^1.96.0"
2323
},
2424
"activationEvents": [
2525
"onLanguage:javascriptreact",
@@ -43,14 +43,19 @@
4343
"package": "rm -f react-forgive-0.0.0.vsix && vsce package --yarn",
4444
"postinstall": "cd client && yarn install && cd ../server && yarn install && cd ..",
4545
"pretest": "yarn run compile && yarn run lint",
46-
"test": "echo 'no tests'",
46+
"test": "vscode-test",
4747
"vscode:prepublish": "yarn run compile",
4848
"watch": "scripts/build.mjs --watch"
4949
},
5050
"devDependencies": {
5151
"@eslint/js": "^9.13.0",
52+
"@types/mocha": "^10.0.10",
5253
"@types/node": "^20",
54+
"@types/vscode": "^1.96.0",
55+
"@vscode/test-cli": "^0.0.10",
56+
"@vscode/test-electron": "^2.4.1",
5357
"eslint": "^9.13.0",
58+
"mocha": "^11.0.1",
5459
"typescript-eslint": "^8.16.0",
5560
"yargs": "^17.7.2"
5661
}

compiler/packages/react-forgive/scripts/server.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const __filename = fileURLToPath(import.meta.url);
1212
const __dirname = path.dirname(__filename);
1313

1414
export const entryPoint = path.join(__dirname, '../server/src/index.ts');
15-
export const outfile = path.join(__dirname, '../dist/extension.js');
15+
export const outfile = path.join(__dirname, '../dist/server.js');
1616
export const config = {
1717
entryPoints: [entryPoint],
1818
outfile,

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
"description": "Experimental LSP server",
66
"license": "MIT",
77
"scripts": {
8-
"build": "echo 'no build'",
8+
"build": "rimraf dist && rollup --config --bundleConfigAsCjs",
99
"test": "echo 'no tests'"
1010
},
1111
"repository": {
1212
"type": "git",
1313
"url": "git+https://github.com/facebook/react.git",
14-
"directory": "compiler/packages/react-forgive-server"
14+
"directory": "compiler/packages/react-forgive"
1515
},
1616
"dependencies": {
17+
"@babel/core": "^7.26.0",
18+
"@babel/parser": "^7.26.0",
19+
"@babel/plugin-syntax-typescript": "^7.25.9",
20+
"@babel/types": "^7.26.0",
21+
"cosmiconfig": "^9.0.0",
22+
"prettier": "^3.3.3",
1723
"vscode-languageserver": "^9.0.1",
1824
"vscode-languageserver-textdocument": "^1.0.12"
1925
}

0 commit comments

Comments
 (0)