Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VS Code workspace config #43851

Closed
wants to merge 1 commit into from
Closed

Conversation

huntie
Copy link
Member

@huntie huntie commented Apr 4, 2024

Summary:

Summary

Adds a react-native.code-workspace workspace file when using VS Code. This disables the built-in TypeScript Language Service for .js files, recommends extensions, enables formatOnSave, and configures Flow language support.

We will recommend this workspace config in our contributing guide: facebook/react-native-website#4075.

Motivation

This is a DevX benefit for React Native contributors using open source VS Code — in particular to help with recent/trivial papercuts in PRs such as inserting a final newline in files (configured by EditorConfig).

Recommended extensions

NOTE: The recommended extensions list is currently minimal — happy to extend this now or in future, but let's aim to keep these conservative.

  • Flow — language support
  • EditorConfig — formatting based on .editorconfig, all file types
  • Prettier — formatting for JS* files
  • ESLint — linter for JS* files

Why react-native.code-workspace?

.code-workspace files have slight extra behaviours over a .vscode/ directory:

  • Allows user to opt-in or skip.
  • Allows double-click launching from file managers.
  • Allows base folder (and any subfolders in future) to be opened with local file tree scope (useful in fbsource!)
  • (Minor point) Single config file over multiple files.

https://code.visualstudio.com/docs/editor/workspaces

Changelog: [Internal]

Test plan

Aganst a new unconfigured copy of Visual Studio Code Insiders.

Without workspace config

.js files raise errors by default (built-in TypeScript language service)

image

❌ When using the Flow VS Code extension, the wrong version (global) of Flow is used.

With workspace config

✅ Workspace config is suggested when folder is opened in VS Code

image

✅ Dialog is shown on workspace launch with recommended VS Code extensions

image

✅ Built-in TypeScript Language Service is disabled for .js files
✅ Flow language support is configured correctly against flow version in package.json

image
image

Differential Revision: D55698495

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 4, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D55698495

Summary:

## Summary

Adds and recommends use of `react-native.code-workspace` file when using VS Code. This disables the built-in TypeScript Language Service for `.js` files, recommends extensions, enables `formatOnSave`, and configures Flow language support.

**Motivation**

This is a DevX benefit for **React Native contributors** using open source VS Code — in particular to help with recent/trivial papercuts in PRs such as inserting a final newline in files (configured by EditorConfig).

**Recommended extensions**

NOTE: The recommended extensions list is currently minimal — happy to extend this now or in future, but let's aim to keep these conservative.

- Flow — language support
- EditorConfig — formatting based on `.editorconfig`, all file types
- Prettier — formatting for JS* files
- ESLint — linter for JS* files
- Kotlin — language support

**Why `react-native.code-workspace`?**

`.code-workspace` files have slight extra behaviours over a `.vscode/` directory:
- Allows user to opt-in or skip.
- Allows double-click launching from file managers.
- Allows base folder (and any subfolders in future) to be opened with local file tree scope (useful in fbsource!)
- (Minor point) Single config file over multiple files.

https://code.visualstudio.com/docs/editor/workspaces

Changelog: [Internal]

## Test plan

Aganst a new unconfigured copy of Visual Studio Code Insiders.

**Without workspace config**

❌ `.js` files raise errors by default (built-in TypeScript language service)

 {F1478195672} 

❌ When using the Flow VS Code extension, the wrong version (global) of Flow is used.

**With workspace config**

✅ Workspace config is suggested when folder is opened in VS Code

 {F1478194795} 

✅ Dialog is shown on workspace launch with recommended VS Code extensions

{F1478196003} 

✅ Built-in TypeScript Language Service is disabled for `.js` files
✅ Flow language support is configured correctly against `flow` version in `package.json`

{F1478291085}
{F1478200649}

Differential Revision: D55698495
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D55698495

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 9c00d6d.

Copy link

github-actions bot commented Apr 4, 2024

This pull request was successfully merged by @huntie in 9c00d6d.

When will my fix make it into a release? | How to file a pick request?

vzaidman added a commit to facebook/react that referenced this pull request Jun 13, 2024
### Summary

Similarly to what has been done on the `react-native` repo in
facebook/react-native#43851, this PR adds a
`react.code-workspace` workspace file when using VSCode.

This disables the built-in TypeScript Language Service for `.js`, `.ts`,
and `.json` files, recommends extensions, enables `formatOnSave`,
excludes certain files in search, and configures Flow language support.

### Motivation

This is a DevX benefit for **React contributors** using open source VS
Code. Without this, it takes quite a long time to set up the environment
in vscode to work well.

For me the following two points took around an hour each to figure out,
but for others it may take even more (screenshots can be found below):
* Search with "files to include" was searching in ignored files
(compiled/generated)
* Configure language validation and prettier both in "packages" that use
flow and in the "compiler" folder that uses typescript.

### Recommended extensions

NOTE: The recommended extensions list is currently minimal — happy to
extend this now or in future, but let's aim to keep these conservative
at the moment.

* Flow — language support
* EditorConfig — formatting based on `.editorconfig`, all file types
* Prettier — formatting for JS* files
* ESLint — linter for JS* files

### Why `react.code-workspace`?

`.code-workspace` files have slight extra behaviours over a `.vscode/`
directory:

* Allows user to opt-in or skip.
* Allows double-click launching from file managers.
* Allows base folder (and any subfolders in future) to be opened with
local file tree scope (useful in fbsource!)
* (Minor point) Single config file over multiple files.
https://code.visualstudio.com/docs/editor/workspaces

### Test plan
Against a new un-configured copy of Visual Studio Code Insiders.

**Without workspace config**

❌ .js files raise errors by default (built-in TypeScript language
service)
❌ When using the Flow VS Code extension, the wrong version (global) of
Flow is used.
<img width="978" alt="Screenshot 2024-06-10 at 16 03 59"
src="https://github.com/facebook/react/assets/5188459/17e19ba4-bac2-48ea-9b35-6b4b6242bcc1">

❌ Searching in excluded files when the "include" field is specified
<img width="502" alt="Screenshot 2024-06-10 at 15 41 24"
src="https://github.com/facebook/react/assets/5188459/00248755-7905-41bc-b303-498ddba82108">

**With workspace config**

✅ Built-in TypeScript Language Service is disabled for .js files, but
still enabled for .ts[x] files
![Screen Recording 2024-06-13 at 12 21
24](https://github.com/facebook/react/assets/5188459/6048218c-f316-44cd-8771-d2d0e848991d)

✅ Flow language support is configured correctly against flow version in
package.json
<img width="993" alt="Screenshot 2024-06-10 at 16 03 44"
src="https://github.com/facebook/react/assets/5188459/b54e143c-a013-4e73-8995-3af7b5a03e36">

✅ Does not search in excluded files when the "include" field is
specified
<img width="555" alt="Screenshot 2024-06-10 at 15 39 18"
src="https://github.com/facebook/react/assets/5188459/dd3e5344-84fb-4b5d-8689-4c8bd28168e0">

✅ Workspace config is suggested when folder is opened in VS Code

![image](https://github.com/facebook/react/assets/5188459/7434261f-1057-4954-9885-b057a10684ad)

✅ Dialog is shown on workspace launch with recommended VS Code
extensions
<img width="580" alt="Screenshot 2024-06-10 at 15 40 52"
src="https://github.com/facebook/react/assets/5188459/c6406fb6-92a0-47f1-8497-4ffe899bb6a9">
@huntie huntie deleted the export-D55698495 branch September 9, 2024 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants