-
Notifications
You must be signed in to change notification settings - Fork 47.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init basic LSP. At the moment the extension doesn't do anything interesting, but it does compile successfully.
- Loading branch information
Showing
14 changed files
with
663 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
**/node_modules | ||
client | ||
server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ignore-engines true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as path from 'path'; | ||
import {ExtensionContext, window as Window} from 'vscode'; | ||
|
||
import { | ||
LanguageClient, | ||
LanguageClientOptions, | ||
ServerOptions, | ||
TransportKind, | ||
} from 'vscode-languageclient/node'; | ||
|
||
let client: LanguageClient; | ||
|
||
export function activate(context: ExtensionContext) { | ||
const serverModule = context.asAbsolutePath(path.join('dist', 'server.js')); | ||
|
||
// If the extension is launched in debug mode then the debug server options are used | ||
// Otherwise the run options are used | ||
const serverOptions: ServerOptions = { | ||
run: { | ||
module: serverModule, | ||
transport: TransportKind.ipc, | ||
options: {cwd: process.cwd()}, | ||
}, | ||
debug: { | ||
module: serverModule, | ||
transport: TransportKind.ipc, | ||
options: {cwd: process.cwd()}, | ||
}, | ||
}; | ||
|
||
const clientOptions: LanguageClientOptions = { | ||
documentSelector: [ | ||
{scheme: 'file', language: 'javascriptreact'}, | ||
{scheme: 'file', language: 'typescriptreact'}, | ||
], | ||
progressOnInitialization: true, | ||
}; | ||
|
||
// Create the language client and start the client. | ||
try { | ||
client = new LanguageClient( | ||
'react-forgive', | ||
'React Analyzer', | ||
serverOptions, | ||
clientOptions, | ||
); | ||
} catch { | ||
Window.showErrorMessage( | ||
`React Analyzer couldn't be started. See the output channel for details.`, | ||
); | ||
return; | ||
} | ||
|
||
client.registerProposedFeatures(); | ||
client.start(); | ||
} | ||
|
||
export function deactivate(): Thenable<void> | undefined { | ||
if (client !== undefined) { | ||
return client.stop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
compiler/packages/react-forgive/server/src/compiler/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import type * as BabelCore from '@babel/core'; | ||
import {parseAsync, transformFromAstAsync} from '@babel/core'; | ||
import BabelPluginReactCompiler, { | ||
type PluginOptions, | ||
} from 'babel-plugin-react-compiler/src'; | ||
import * as babelParser from 'prettier/plugins/babel.js'; | ||
import estreeParser from 'prettier/plugins/estree'; | ||
import * as typescriptParser from 'prettier/plugins/typescript'; | ||
import * as prettier from 'prettier/standalone'; | ||
|
||
type CompileOptions = { | ||
text: string; | ||
file: string; | ||
options: PluginOptions | null; | ||
}; | ||
export async function compile({ | ||
text, | ||
file, | ||
options, | ||
}: CompileOptions): Promise<BabelCore.BabelFileResult> { | ||
const ast = await parseAsync(text, { | ||
sourceFileName: file, | ||
parserOpts: { | ||
plugins: ['typescript', 'jsx'], | ||
}, | ||
sourceType: 'module', | ||
}); | ||
const plugins = | ||
options != null | ||
? [[BabelPluginReactCompiler, options]] | ||
: [[BabelPluginReactCompiler]]; | ||
const result = await transformFromAstAsync(ast, text, { | ||
filename: file, | ||
highlightCode: false, | ||
retainLines: true, | ||
plugins, | ||
sourceType: 'module', | ||
sourceFileName: file, | ||
}); | ||
if (result?.code == null) { | ||
throw new Error( | ||
`Expected BabelPluginReactCompiler to compile successfully, got ${result}`, | ||
); | ||
} | ||
result.code = await prettier.format(result.code, { | ||
semi: false, | ||
parser: 'babel-ts', | ||
plugins: [babelParser, estreeParser, typescriptParser], | ||
}); | ||
return result; | ||
} |
25 changes: 25 additions & 0 deletions
25
compiler/packages/react-forgive/server/src/compiler/options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { | ||
parsePluginOptions, | ||
type PluginOptions, | ||
} from 'babel-plugin-react-compiler/src'; | ||
import {cosmiconfigSync} from 'cosmiconfig'; | ||
|
||
export function resolveReactConfig(projectPath: string): PluginOptions | null { | ||
const explorerSync = cosmiconfigSync('react', { | ||
searchStrategy: 'project', | ||
cache: true, | ||
}); | ||
const result = explorerSync.search(projectPath); | ||
if (result != null) { | ||
return parsePluginOptions(result.config); | ||
} else { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
{ | ||
"extends": "@tsconfig/strictest/tsconfig.json", | ||
"compilerOptions": { | ||
"module": "CommonJS", | ||
"moduleResolution": "node", | ||
"outDir": "dist", | ||
"module": "ES2015", | ||
"moduleResolution": "Bundler", | ||
"rootDir": "../../..", | ||
"noEmit": true, | ||
"jsx": "react-jsxdev", | ||
"lib": ["ES2020"], | ||
"target": "ES2020", | ||
"target": "ES2015", | ||
"sourceMap": false, | ||
"removeComments": true, | ||
|
||
"strictNullChecks": false | ||
}, | ||
"exclude": ["node_modules", ".vscode-test"], | ||
"include": ["src/**/*.ts"], | ||
"include": ["src/**/*.ts"] | ||
} |
Oops, something went wrong.