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

[pull] master from vuejs:master #137

Merged
merged 11 commits into from
Aug 10, 2024
Merged

[pull] master from vuejs:master #137

merged 11 commits into from
Aug 10, 2024

Conversation

pull[bot]
Copy link

@pull pull bot commented Aug 9, 2024

See Commits and Changes for more details.


Created by pull[bot]

Can you help keep this open source service alive? 💖 Please sponsor : )

Summary by CodeRabbit

  • New Features

    • Added configuration option for inlay hints in destructured properties for Vue components.
    • Introduced a new plugin for handling Vue root tags and embedded code.
    • Implemented inlay hints support for enhanced contextual information in the editor.
  • Bug Fixes

    • Improved type inference and handling of destructured variables in script setup contexts.
  • Documentation

    • Enhanced clarity in JSON configurations for Vue directives by adding valueSet properties across multiple language localizations.
  • Refactor

    • Streamlined various functions and interfaces to improve readability and maintainability, including updates to method signatures and parameter handling in the plugin architecture.
  • Tests

    • Updated testing framework to focus on line-by-line comparisons for better accuracy in assertions.

Copy link

stackblitz bot commented Aug 9, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

coderabbitai bot commented Aug 9, 2024

Walkthrough

This update introduces enhancements to Vue's language services, particularly focusing on inlay hints for destructured properties and improved handling of Vue single-file components (SFCs). Key modifications include a new configuration option for inlay hints, refactorings in TypeScript code generation functions, and various refinements to existing plugins. These changes aim to enhance developer experience by providing better contextual information and improving the overall functionality of the Vue development environment.

Changes

File(s) Change Summary
extensions/vscode/package.json Added vue.inlayHints.destructuredProps configuration option for inlay hints.
packages/language-core/lib/codegen/common.ts Refactored collectVars to collectIdentifiers, enhancing identifier collection from AST.
packages/language-core/lib/codegen/script/context.ts Exported HelperType interface; introduced inlayHints variable for managing hints.
packages/language-core/lib/codegen/script/index.ts Changed return type of generateScript to include ScriptCodegenContext; updated inlay hint logic.
packages/language-core/lib/codegen/types.ts Introduced InlayHintInfo interface for structured inlay hints metadata.
packages/language-service/index.ts Replaced createVueVisualizeHiddenCallbackParamPlugin with createVueInlayHintsPlugin.
packages/language-service/lib/plugins/vue-inlayhints.ts New plugin for providing inlay hints specific to Vue components.
packages/language-service/data/template/*.json Added valueSet property to directives in various localization files.
test-workspace/language-service/inlay-hint/destructured-props/entry.vue Introduced a Vue component utilizing destructured props with TypeScript support.
test-workspace/tsc/vue3/#4646/*.vue Created several Vue components demonstrating Composition API and TypeScript integration.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Editor
    participant VuePlugin

    Developer->>Editor: Writes Vue code
    Editor->>VuePlugin: Requests inlay hints
    VuePlugin-->>Editor: Returns inlay hints for destructured props
    Editor->>Developer: Displays inlay hints
Loading

🐇 In the garden, where ideas bloom,
A hint of code dispels the gloom.
With props now clear, oh what delight!
In Vue's embrace, the code takes flight.
A playful hop, a joyful cheer,
For every change that draws us near! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Outside diff range, codebase verification and nitpick comments (5)
test-workspace/tsc/vue3/vuejs#4646/parent.vue (1)

2-2: Consider removing the @ts-nocheck directive.

The @ts-nocheck directive disables TypeScript checks for the entire file. If possible, remove it and address specific TypeScript issues to benefit from type checking.

test-workspace/language-service/inlay-hint/destructured-props/entry.vue (1)

2-2: Consider removing the @ts-nocheck directive.

The @ts-nocheck directive disables TypeScript checks for the entire file. If possible, remove it and address specific TypeScript issues to benefit from type checking.

packages/language-core/lib/codegen/template/objectProperty.ts (1)

18-18: Update function calls to include the shouldBeConstant parameter.

The generateObjectProperty function has been updated with a new parameter shouldBeConstant, but the current calls to this function do not include this parameter. To maintain backward compatibility, ensure that all calls to generateObjectProperty are updated to handle the new parameter.

  • Files to update:
    • packages/language-core/lib/codegen/template/element.ts
    • packages/language-core/lib/codegen/template/elementProps.ts
    • packages/language-core/lib/codegen/template/index.ts
Analysis chain

Ensure backward compatibility with the new parameter.

The addition of the shouldBeConstant parameter changes the function signature. Verify that all calls to generateObjectProperty are updated to handle this new parameter.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `generateObjectProperty` are updated to include the new parameter.

# Test: Search for the function usage. Expect: Correct handling of the new parameter.
rg --type ts -A 5 $'generateObjectProperty'

Length of output: 4133


Script:

#!/bin/bash
# Description: Verify if the `shouldBeConstant` parameter is included in all calls to `generateObjectProperty`.

# Test: Search for the function usage and check if the new parameter is included.
rg --type ts -A 5 $'generateObjectProperty' | grep 'shouldBeConstant'

Length of output: 66


Script:

#!/bin/bash
# Description: List all calls to `generateObjectProperty` to manually verify the inclusion of the `shouldBeConstant` parameter.

# List all occurrences of `generateObjectProperty` and show surrounding lines for context.
rg --type ts -A 5 $'generateObjectProperty'

Length of output: 4133

packages/language-core/lib/virtualFile/vueFile.ts (1)

53-53: Consider lazy initialization for getSnapshot.

The getSnapshot is initialized in the constructor. Consider lazy initialization if the initial snapshot is large or expensive to compute.

- this.getSnapshot = signal(initSnapshot);
+ this.getSnapshot ||= signal(initSnapshot);
packages/language-service/lib/plugins/vue-inlayhints.ts (1)

9-14: Define capabilities more explicitly.

The capabilities object is currently empty. Consider defining specific capabilities that this plugin supports to enhance clarity and maintainability.

- inlayHintProvider: {},
+ inlayHintProvider: {
+   resolveProvider: false,
+ },
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 67be01c and 0f14cde.

Files selected for processing (50)
Files skipped from review due to trivial changes (3)
  • packages/language-service/data/template/fr.json
  • packages/language-service/data/template/zh-cn.json
  • test-workspace/tsc/vue2/tsconfig.json
Additional context used
Biome
packages/language-service/lib/plugins/vue-inlayhints.ts

[error] 116-116: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (76)
test-workspace/tsc/vue3/vuejs#4646/child2.vue (1)

3-4: Verify the usage of defineModel.

The defineModel function is used to create a reactive variable other. Ensure that this function is correctly defined and used elsewhere in the codebase.

test-workspace/language-service/complete/vuejs#4639/input/entry.vue (1)

5-5: Confirm the purpose of the incomplete @click directive.

The @click. directive is incomplete, which seems intentional for testing purposes. Ensure that this aligns with the intended test case for completion functionality.

Verification successful

Incomplete @click Directive is Intentional for Testing

The incomplete @click directive in entry.vue is indeed intentional and aligns with the test case for completion functionality. It is used to test the completion of the capture modifier, as indicated by the comment ^complete: capture found in the same file.

  • test-workspace/language-service/complete/#4639/input/entry.vue: The incomplete directive is accompanied by a comment suggesting it tests the completion of capture.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Confirm the purpose of the incomplete `@click` directive.

# Test: Search for related test cases or documentation. Expect: References explaining the test case.
rg --type vue --type md $'@click.' -A 5

Length of output: 66


Script:

#!/bin/bash
# Description: Confirm the purpose of the incomplete `@click` directive.

# Test: Search for related test cases or documentation. Expect: References explaining the test case.
rg '@click\.' --glob '*.vue' --glob '*.md' -A 5

Length of output: 926

test-workspace/language-service/complete/vuejs#4639/output/entry.vue (1)

5-5: Confirm the correctness of the @click.capture directive.

The @click.capture directive seems to be the expected result for the completion test case. Verify that this matches the intended functionality.

test-workspace/tsc/vue3/vuejs#4668/child.vue (1)

3-7: Ensure correct usage of defineSlots.

The defineSlots function is used to define slots with TypeScript types. Ensure that this function is supported in the current setup and that the types are correctly defined.

packages/language-core/lib/codegen/types.ts (1)

1-9: Interface InlayHintInfo is well-defined.

The interface uses optional properties effectively and is consistent with TypeScript best practices.

test-workspace/tsc/vue3/vuejs#4646/child.vue (1)

4-12: Verify the usage of defineModel and exactType.

Ensure that defineModel and exactType are correctly implemented and supported in your setup. The type casting and usage appear correct, but verify their integration and functionality.

test-workspace/language-service/complete/directives/input/entry.vue (1)

1-12: Test case for directive completion.

This file is structured as a test case for verifying the autocompletion of Vue directives. Each directive is intentionally incomplete, with comments indicating the expected completion. Ensure that the language service correctly identifies and suggests these completions.

test-workspace/language-service/complete/directives/output/entry.vue (1)

1-12: Test case for verifying directive completion output.

This file is structured as a test case for verifying the output of directive autocompletion in a language service. Each directive is complete, and the comments serve as a reference for expected behavior. Ensure that the language service correctly matches these completions.

test-workspace/tsc/vue3/vuejs#4668/main.vue (1)

1-16: Test case for dynamic slots and type checking.

This file is structured as a test case for a specific issue or feature related to dynamic slot names and type checking in Vue 3. The use of exactType indicates a focus on ensuring type correctness. Verify that the language service handles these scenarios as expected.

test-workspace/tsc/vue3/vuejs#4646/parent.vue (1)

8-14: Ensure exactType is implemented correctly.

The exactType function is imported but not defined in this file. Verify that it is correctly implemented and used elsewhere in the codebase.

Verification successful

exactType is correctly declared as a TypeScript utility. The exactType function is declared in test-workspace/tsc/shared.d.ts as a type-checking utility, which is typical for TypeScript projects. It is used for compile-time type validation and does not require a runtime implementation.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the `exactType` function.

# Test: Search for the `exactType` function definition. Expect: A valid function definition.
rg --type ts -A 5 $'function exactType'

Length of output: 593

test-workspace/language-service/inlay-hint/destructured-props/entry.vue (1)

5-9: Verify the use of defineProps with destructuring.

Ensure that destructuring defineProps works as expected and that the destructured properties are used correctly throughout the script.

Verification successful

Destructured Props Usage Verified

The destructured properties foo, bar, and props from defineProps are used throughout the Vue component. The usage appears consistent with expected patterns, indicating that destructuring is working as intended. Here are some key points of usage:

  • foo, bar, and props are used in various contexts, such as object properties and function parameters.
  • The inlay hints suggest that these properties are correctly recognized and utilized within the component logic.

No issues were found with the destructuring and usage of these properties.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of destructured props with `defineProps`.

# Test: Search for destructured props usage in Vue components. Expect: Correct usage patterns.
rg --type vue -A 5 $'const { foo, bar, ...props } = defineProps'

Length of output: 198


Script:

#!/bin/bash
# Description: Correct the search pattern for destructured props in Vue components.

# Test: Search for destructured props usage in Vue components with a corrected pattern.
rg --type vue -A 5 'const \{ foo, bar, \.\.\.props \} = defineProps'

Length of output: 98


Script:

#!/bin/bash
# Description: Search for destructured props in Vue components without specifying file type.

# Find all .vue files and search for the destructuring pattern within them.
fd --extension vue --exec rg -A 5 'const \{ foo, bar, \.\.\.props \} = defineProps' {}

Length of output: 187


Script:

#!/bin/bash
# Description: Find usage of destructured props in the Vue component where they are defined.

# Locate the file containing the destructuring pattern and search for the usage of `foo`, `bar`, and `props`.
fd --extension vue --exec rg -l 'const \{ foo, bar, \.\.\.props \} = defineProps' {} | xargs -I {} rg -A 5 -e 'foo' -e 'bar' -e 'props' {}

Length of output: 1091

packages/language-core/lib/codegen/template/objectProperty.ts (1)

21-34: Review logic for handling constant expressions.

The logic for handling constant expressions is conditionally applied. Ensure this logic is correctly implemented and tested, particularly when shouldBeConstant is true.

packages/language-core/lib/virtualFile/vueFile.ts (3)

20-21: Ensure correct usage of computed properties.

The getVueSfc and sfc properties now use getSnapshot(). Verify that this change does not affect the expected behavior of these computations.


22-30: Review the new getMappings computation.

The getMappings method now uses a computed function. Ensure that allCodeFeatures is correctly integrated and that the computation logic aligns with the intended functionality.

Verification successful

Integration of allCodeFeatures in getMappings is correct.

The allCodeFeatures object, defined in shared.ts, is consistently used across various modules to provide metadata or capabilities. Its integration into the getMappings method aligns with its intended functionality. No issues found with the current implementation.

  • allCodeFeatures is imported from shared.ts and used consistently across the codebase.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of `allCodeFeatures` in `getMappings`.

# Test: Search for the definition and usage of `allCodeFeatures`. Expect: Correct integration in `getMappings`.
rg --type typescript -A 5 $'allCodeFeatures'

Length of output: 78


Script:

#!/bin/bash
# Description: Search for the definition and usage of `allCodeFeatures` in TypeScript files.

# Test: Find the definition of `allCodeFeatures`.
rg 'allCodeFeatures' -t ts -A 5

Length of output: 5794


31-31: Verify the computedEmbeddedCodes integration.

The getEmbeddedCodes method now uses computedEmbeddedCodes. Ensure that this integration aligns with the intended functionality.

Verification successful

Integration of computedEmbeddedCodes Verified

The integration of computedEmbeddedCodes into the getEmbeddedCodes method is correct. The function is imported and used appropriately, with parameters matching its definition.

  • computedEmbeddedCodes is defined in computedEmbeddedCodes.ts.
  • It is imported and used in vueFile.ts with the expected parameters.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of `computedEmbeddedCodes` in `getEmbeddedCodes`.

# Test: Search for the definition and usage of `computedEmbeddedCodes`. Expect: Correct integration in `getEmbeddedCodes`.
rg --type typescript -A 5 $'computedEmbeddedCodes'

Length of output: 84


Script:

#!/bin/bash
# Corrected script: Verify the integration of `computedEmbeddedCodes` in `getEmbeddedCodes`.

# Search for the definition of `computedEmbeddedCodes` in the codebase.
rg --type ts -A 5 'computedEmbeddedCodes'

# Search for the usage of `computedEmbeddedCodes` in the vueFile.ts file.
rg --type ts 'computedEmbeddedCodes' packages/language-core/lib/virtualFile/vueFile.ts

Length of output: 1788

packages/language-core/lib/plugins/vue-root-tags.ts (2)

11-16: Ensure getEmbeddedCodes returns correct structure.

The getEmbeddedCodes method returns an array with a single embedded code object. Verify that this structure aligns with the expected format for embedded codes.

Verification successful

The getEmbeddedCodes method is correctly implemented.

The method in vue-root-tags.ts returns an array of objects with id and lang properties, consistent with the structure used in other plugins. No changes are needed.

  • File: packages/language-core/lib/plugins/vue-root-tags.ts
  • Lines: 11-16
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the expected structure for embedded codes returned by `getEmbeddedCodes`.

# Test: Search for the usage and structure of embedded codes. Expect: Correct format as used in other plugins.
rg --type typescript -A 5 $'getEmbeddedCodes'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify the expected structure for embedded codes returned by `getEmbeddedCodes`.

# Test: Search for the usage and structure of embedded codes. Expect: Correct format as used in other plugins.
rg --type ts -A 5 $'getEmbeddedCodes'

Length of output: 5908


18-65: Review resolveEmbeddedCode logic for correctness.

The resolveEmbeddedCode method processes embedded files. Ensure that the logic correctly handles all block types and that the replaceSourceRange function is used appropriately.

packages/language-core/lib/plugins.ts (1)

24-24: Verify the integration of vueRootTagsPlugin.

The vueRootTagsPlugin is added to the list of plugins. Ensure that its integration aligns with the intended functionality and does not conflict with other plugins.

packages/language-core/lib/codegen/common.ts (2)

48-55: LGTM!

The refactoring of collectVars to utilize collectIdentifiers enhances the precision of identifier collection by working with node structures. This change is consistent with the intended improvements.


58-84: Efficient handling of identifiers.

The collectIdentifiers function is well-structured, efficiently handling various AST node types. The use of default parameters enhances flexibility.

packages/language-service/tests/complete.ts (2)

11-11: Enhanced line retrieval functionality.

The getLineText function effectively combines newline normalization with line retrieval, improving the precision of test assertions.


86-86: Improved test accuracy with line-by-line comparison.

The use of getLineText for line-by-line comparison in test assertions enhances the accuracy and focus of the tests.

packages/language-service/lib/plugins/data.ts (1)

42-45: Enhanced attribute binding flexibility.

The addition of : and v-bind: prefixes to applicable attributes improves flexibility in attribute handling, aligning with Vue.js conventions.

packages/language-service/tests/utils/createTester.ts (1)

42-42: Enable inlay hints for destructured properties.

The addition of 'vue.inlayHints.destructuredProps': true enhances developer experience by providing additional context in the code editor.

packages/language-core/lib/codegen/script/context.ts (2)

6-6: Export HelperType interface.

Exporting HelperType increases its accessibility and usability across other modules.


Line range hint 106-118:
Introduce inlayHints for script code generation context.

The addition of inlayHints suggests an enhancement in managing inlay hints within the script code generation context.

packages/language-core/lib/types.ts (2)

Line range hint 21-21:
Remove __hint from VueCodeInformation.

The removal of __hint simplifies the VueCodeInformation interface, potentially reducing complexity in related implementations.


95-95: Add content to Sfc interface.

The addition of content enhances the representation of single-file components (SFCs) by explicitly including the main content.

packages/language-core/lib/plugins/vue-tsx.ts (1)

Line range hint 143-170:
Refactor to use generator pattern improves clarity and performance.

The refactoring of the createTsx function to use a generator pattern enhances the code's clarity and potentially improves performance by processing values as they are produced. The implementation is correct, and the final return statement ensures all necessary data is included.

packages/language-core/lib/codegen/template/context.ts (1)

Line range hint 114-126:
Addition of inlayHints enhances template code generation.

The inclusion of the inlayHints array in the createTemplateCodegenContext function extends its capabilities, allowing for better management of inlay hint information. This enhancement is beneficial for editor features and tooling integration, aligning well with the function's purpose.

packages/language-core/lib/codegen/template/elementEvents.ts (1)

154-168: Refactor inlay hint generation for clarity and maintainability.

The refactoring of the generateEventExpression function to directly push inlay hints onto the ctx.inlayHints array improves the code's clarity and maintainability. The logic remains consistent, ensuring that the functionality related to inlay hints is preserved.

packages/language-core/lib/codegen/script/globalTypes.ts (1)

103-103: Addition of __VLS_tryAsConstant looks good.

The function __VLS_tryAsConstant enhances the type system by providing a utility for treating values as constants. This addition appears to be a non-breaking enhancement.

packages/language-core/lib/codegen/template/interpolation.ts (1)

15-15: Enhanced generateInterpolation function signature is approved.

The modification to allow an offset parameter in the data function enhances flexibility. Ensure that all calls to generateInterpolation are updated accordingly to pass the offset.

Also applies to: 56-56

Verification successful

All generateInterpolation function calls are updated with the new signature.

The function calls across the codebase have been verified to include the offset parameter, ensuring consistency with the enhanced function signature.

  • Calls in objectProperty.ts, elementEvents.ts, element.ts, vIf.ts, vFor.ts, templateChild.ts, slotOutlet.ts, propertyAccess.ts, elementDirectives.ts, and elementProps.ts are all updated as expected.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `generateInterpolation` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type typescript -A 5 $'generateInterpolation'

Length of output: 84


Script:

#!/bin/bash
# Description: Verify all function calls to `generateInterpolation` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --glob '*.ts' -A 5 'generateInterpolation'

Length of output: 15029

packages/language-core/lib/virtualFile/computedEmbeddedCodes.ts (1)

9-9: Renaming to computedEmbeddedCodes is approved.

The function name change from computedFiles to computedEmbeddedCodes better reflects its purpose related to embedded codes in Vue components. This improves code clarity.

packages/language-core/lib/codegen/script/index.ts (1)

Line range hint 52-148:
Update the return type and inlay hint logic.

The return type of generateScript has been updated to Generator<Code, ScriptCodegenContext>, which improves the utility by providing additional context. The new inlay hint logic, which directly appends to ctx.inlayHints, simplifies the code and enhances clarity. Ensure that the changes align with the intended functionality and check for any potential impacts on the rest of the codebase.

Verification successful

Verification Successful: Updated generateScript Function

The generateScript function is correctly utilized in packages/language-core/lib/plugins/vue-tsx.ts, and the updated return type Generator<Code, ScriptCodegenContext> along with the new inlay hint logic are consistent with the intended functionality. No issues found regarding the integration of these changes.

  • File: packages/language-core/lib/plugins/vue-tsx.ts
  • Usage Context: The function is invoked with appropriate arguments, ensuring the updated logic is correctly applied.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage and impact of the updated `generateScript` function.

# Test: Search for the `generateScript` function usage. Expect: Consistent usage with updated return type.
rg --type typescript -A 5 $'generateScript'

Length of output: 77


Script:

#!/bin/bash
# Description: Verify the usage and impact of the updated `generateScript` function.

# Test: Search for the `generateScript` function usage. Expect: Consistent usage with updated return type.
rg --type ts -A 5 $'generateScript'

Length of output: 9479

packages/language-service/lib/plugins/vue-sfc.ts (2)

Line range hint 46-227:
Remove Provide interface and update create function.

The Provide interface has been removed, and the create function's return type has been updated. This suggests a simplification of the plugin's API. Ensure that this change does not affect any dependent code and aligns with the overall design goals.


14-14: Update documentSelector to target vue-root-tags.

The documentSelector has been changed from ['vue'] to ['vue-root-tags'], indicating a more specific targeting of Vue components. This change is likely intended to improve the plugin's focus and performance. Verify that this change aligns with the intended functionality and does not inadvertently exclude necessary documents.

Verification successful

The documentSelector change in vue-sfc.ts is specific and isolated.

The update to ['vue-root-tags'] in vue-sfc.ts is localized to this file and does not affect other parts of the codebase that use different selectors. This change appears to be intentional to focus on specific Vue components. Ensure that this aligns with the intended functionality of the plugin.

  • vue-sfc.ts uses ['vue-root-tags'].
  • vue-template.ts uses ['html', 'markdown'].
  • nodeClientMain.ts uses a variable documentSelector.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the updated `documentSelector` on the plugin's functionality.

# Test: Search for the usage of `documentSelector` in the codebase. Expect: Consistent usage with updated selector.
rg --type typescript -A 5 $'documentSelector'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify the impact of the updated `documentSelector` on the plugin's functionality.

# Test: Search for the usage of `documentSelector` in the codebase. Expect: Consistent usage with updated selector.
rg --type ts -A 5 $'documentSelector'

Length of output: 1720

packages/language-core/lib/virtualFile/computedSfc.ts (1)

13-26: Rename parameter to getSnapshot and add content getter.

The parameter snapshot has been renamed to getSnapshot, enhancing clarity. The addition of the content getter encapsulates snapshot retrieval logic, improving usability. Ensure that these changes are consistent throughout the codebase and align with the intended functionality.

Verification successful

Rename parameter to getSnapshot and add content getter verified.

The renaming of the snapshot parameter to getSnapshot and the addition of the content getter in the computedSfc function are consistent with its usage in the codebase. The changes align with the intended functionality, as seen in the vueFile.ts file.

  • computedSfc is defined with getSnapshot in computedSfc.ts.
  • computedSfc is used with getSnapshot in vueFile.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the renaming of `snapshot` to `getSnapshot` and the addition of the `content` getter.

# Test: Search for the `computedSfc` function usage. Expect: Consistent usage with updated parameter and getter.
rg --type typescript -A 5 $'computedSfc'

Length of output: 74


Script:

#!/bin/bash
# Description: Verify the renaming of `snapshot` to `getSnapshot` and the addition of the `content` getter.

# Test: Search for the `computedSfc` function usage. Expect: Consistent usage with updated parameter and getter.
rg --type ts -A 5 $'computedSfc'

Length of output: 3739

packages/language-service/index.ts (3)

204-204: Verify the language mapping change.

The language mapping for 'vue' to 'vue-root-tags' has been updated. Ensure this change is consistent across the codebase and does not break existing functionality.

Verification successful

Language Mapping Change Verified

The language mapping for 'vue-root-tags' appears to be consistently used across the codebase. The search results show that the mapping is present in several files, indicating that the change is integrated throughout the relevant parts of the code.

  • Files with 'vue-root-tags' usage:
    • packages/language-service/index.ts
    • packages/language-core/lib/plugins.ts
    • packages/language-core/lib/plugins/vue-root-tags.ts
    • packages/language-service/lib/plugins/vue-sfc.ts

These files demonstrate that the mapping change is consistently applied, and there is no indication of broken functionality related to this change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistency of language mapping change.

# Test: Search for language mapping usage. Expect: Consistent usage across the codebase.
rg --type typescript -A 5 $'vue-root-tags'

Length of output: 76


Script:

#!/bin/bash
# Description: Verify consistency of language mapping change.

# Test: Search for language mapping usage across the codebase without specifying a file type.
rg -A 5 'vue-root-tags'

Length of output: 2477


28-28: Ensure createVueInlayHintsPlugin is correctly implemented.

The new plugin createVueInlayHintsPlugin is imported. Verify that it is correctly implemented and integrated within the codebase.


199-199: Review the integration of createVueInlayHintsPlugin.

Ensure that the integration of createVueInlayHintsPlugin(ts) aligns with the intended functionality and does not introduce any conflicts.

packages/language-service/scripts/update-html-data.js (1)

307-312: Confirm expanded valueSet conditions are correct.

The valueSet now includes additional directives. Ensure these changes are correct and align with Vue's directive handling.

Verification successful

The expanded valueSet conditions are correct. The conditions align with Vue.js directive handling by including valid directives like v-cloak, v-else, v-once, and v-pre. These are standard Vue.js directives used for rendering control.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify expanded `valueSet` conditions in templateWorker function.

# Test: Check for correctness and alignment with Vue's directive handling. Expect: Correct handling of new directives.
rg --type javascript -A 5 $'valueSet:'

Length of output: 72


Script:

#!/bin/bash
# Correcting the search command to find the valueSet conditions and gather context around it.
fd -e js | xargs rg 'valueSet:' -A 5

Length of output: 1974

packages/language-core/lib/codegen/template/elementProps.ts (1)

Line range hint 272-310:
Parameter Renaming and Logic Update

The parameter inlayHints has been renamed to enableCodeFeatures, and the logic has been updated to handle inlay hints when enableCodeFeatures is true. This change broadens the scope of the parameter, indicating a shift towards enabling multiple code features.

Ensure that all usages of this function in the codebase are updated to reflect this change.

packages/language-core/lib/parsers/scriptSetupRanges.ts (1)

18-18: Enhancement: Handling Destructured Variables

The props object now includes a destructured property to store destructured variable names. This enhancement improves the function's capability to parse script setup ranges with destructured variables.

Ensure that any code relying on parseScriptSetupRanges is updated to handle the new destructured property appropriately.

Also applies to: 236-243

extensions/vscode/package.json (1)

386-390: New Configuration Option: vue.inlayHints.destructuredProps

A new configuration option vue.inlayHints.destructuredProps has been added to control the display of inlay hints for destructured props. This option, set to false by default, enhances code readability and developer experience.

Ensure that this new configuration option is documented appropriately in the project's documentation.

packages/language-core/lib/codegen/script/scriptSetup.ts (1)

416-416: Review the impact of removing NonNullable.

The removal of NonNullable in the generateDefinePropType function allows null or undefined values for the inferred type. This change may affect type safety, especially if the rest of the codebase assumes non-nullable types.

Ensure that the rest of the codebase correctly handles nullable types where this function is used. If necessary, update documentation or add checks to prevent runtime errors.

packages/language-core/lib/codegen/template/element.ts (1)

447-449: Clarify the purpose of new boolean parameters.

The addition of false and true as parameters to the generateComponentSlot function suggests an enhancement in functionality. Ensure these parameters are documented, and their impact on the function's behavior is clear.

Check if these parameters are used consistently across the codebase and if their purpose is documented in the function's comments or documentation.

packages/language-service/lib/plugins/vue-template.ts (5)

162-170: Enhance embedded template handling.

The new logic for handling sourceScript?.generated improves the processing of embedded templates. Ensure that this change does not introduce any regressions and that all edge cases are covered.

Test the handling of various embedded template scenarios to confirm the robustness of this change.


428-435: Optimize tag processing logic.

The new check for isInternalItemId(tag.name) improves efficiency by skipping internal tags. Ensure this logic is consistent with the intended behavior across the codebase.

Review other parts of the code that process tags to ensure consistency and correctness with this new logic.


667-669: Update parameter name for clarity.

The afterHtmlCompletion function now uses document instead of sourceDocument, which improves clarity. Ensure this change is reflected in all related documentation and usage.


Line range hint 740-779: Manage completion items with originals map.

The introduction of the originals map for managing completion items enhances the handling of documentation. Verify that this logic correctly updates and retrieves documentation for completion items.

Test various completion scenarios to ensure that documentation is correctly managed and displayed for all items.


892-894: New function isInternalItemId added.

The isInternalItemId function helps identify internal item IDs. Ensure this function is used appropriately throughout the codebase to maintain consistency.

packages/language-service/data/template/zh-hk.json (3)

1176-1176: Addition of valueSet to v-pre is consistent.

The valueSet: "v" property enhances the categorization of the v-pre directive. This is a consistent and straightforward addition.


1238-1238: Addition of valueSet to v-once is consistent.

The valueSet: "v" property is added to the v-once directive, aligning with the categorization strategy. This change is consistent and well-implemented.


1361-1361: Addition of valueSet to v-cloak is consistent.

The valueSet: "v" property is added to the v-cloak directive, following the same pattern as other directives. This change is consistent and appropriate.

packages/language-service/data/template/ja.json (3)

1176-1176: Addition of valueSet to v-pre is appropriate.

The addition of "valueSet": "v" enhances the metadata for better categorization without affecting functionality.


1238-1238: Addition of valueSet to v-once is appropriate.

The addition of "valueSet": "v" enhances the metadata for better categorization without affecting functionality.


1361-1361: Addition of valueSet to v-cloak is appropriate.

The addition of "valueSet": "v" enhances the metadata for better categorization without affecting functionality.

packages/language-service/data/template/ko.json (3)

1176-1176: LGTM: Addition of "valueSet": "v" to v-pre.

The addition of "valueSet": "v" to the v-pre directive helps categorize it under a common set, enhancing organization.


1238-1238: LGTM: Addition of "valueSet": "v" to v-once.

The inclusion of "valueSet": "v" for v-once aligns with the categorization strategy, enhancing consistency.


1361-1361: LGTM: Addition of "valueSet": "v" to v-cloak.

The addition of "valueSet": "v" to v-cloak is consistent with the categorization of other directives.

packages/language-service/data/template/it.json (3)

1176-1176: Addition of valueSet property to v-pre.

The addition of the valueSet property with the value "v" enhances the metadata for the v-pre directive. This change does not affect the existing functionality but provides a clearer structure for potential future enhancements.


1238-1238: Addition of valueSet property to v-once.

The addition of the valueSet property with the value "v" enhances the metadata for the v-once directive. This change does not affect the existing functionality but provides a clearer structure for potential future enhancements.


1361-1361: Addition of valueSet property to v-cloak.

The addition of the valueSet property with the value "v" enhances the metadata for the v-cloak directive. This change does not affect the existing functionality but provides a clearer structure for potential future enhancements.

packages/language-service/data/template/en.json (3)

1176-1176: Addition of valueSet to v-pre is appropriate.

The addition of "valueSet": "v" enhances the categorization of the v-pre directive, aligning with the overall structure for Vue.js directives.


1238-1238: Addition of valueSet to v-once is appropriate.

The inclusion of "valueSet": "v" helps in categorizing the v-once directive, which can improve the handling and organization of directives.


1361-1361: Addition of valueSet to v-cloak is appropriate.

Adding "valueSet": "v" to the v-cloak directive ensures consistency across directives and enhances their metadata for better categorization.

packages/language-service/data/template/cs.json (3)

1176-1176: Addition of valueSet to v-pre looks good.

The valueSet property categorizes this directive, which can help in organizing and processing directives. Ensure that this change is reflected in any relevant processing logic.


1238-1238: Addition of valueSet to v-once looks good.

The valueSet property provides a standardized categorization for this directive. Verify that any logic relying on this categorization is updated accordingly.


1361-1361: Addition of valueSet to v-cloak looks good.

The inclusion of the valueSet property helps in organizing directives under a common category. Ensure that this change is incorporated into any related processing logic.

packages/language-service/data/template/ru.json (3)

1176-1176: Addition of valueSet for v-pre looks good.

The addition of "valueSet": "v" to v-pre helps categorize it, possibly for enhanced processing or organization. Ensure this aligns with the intended use in the language service.


1238-1238: Addition of valueSet for v-once looks good.

The "valueSet": "v" addition to v-once categorizes it similarly to v-pre. Ensure this categorization aligns with the intended functionality in the language service.


1361-1361: Addition of valueSet for v-cloak looks good.

The "valueSet": "v" addition to v-cloak categorizes it with other directives. Ensure this categorization is consistent with the intended use in the language service.

packages/language-service/data/template/pt.json (3)

1176-1176: Addition of valueSet to v-pre is appropriate.

The addition of valueSet: "v" to the v-pre directive enhances metadata without affecting existing functionality.


1238-1238: Addition of valueSet to v-once is appropriate.

The addition of valueSet: "v" to the v-once directive enhances metadata without affecting existing functionality.


1361-1361: Addition of valueSet to v-cloak is appropriate.

The addition of valueSet: "v" to the v-cloak directive enhances metadata without affecting existing functionality.


export class VueVirtualCode implements VirtualCode {

// sources

id = 'main';

_snapshot: Signal<ts.IScriptSnapshot>;
getSnapshot: Signal<ts.IScriptSnapshot>;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhance encapsulation with a private modifier.

The getSnapshot property is public but could be made private to encapsulate internal state management better.

- getSnapshot: Signal<ts.IScriptSnapshot>;
+ private getSnapshot: Signal<ts.IScriptSnapshot>;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
getSnapshot: Signal<ts.IScriptSnapshot>;
private getSnapshot: Signal<ts.IScriptSnapshot>;

Comment on lines +11 to +19
type foo = foo[string] & typeof foo;
// ^inlayHint: "props."

interface foo extends (typeof foo) {
// ^inlayHint: "props."
foo: string;
foo(foo: string): void;
foo: (foo: string) => void;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using duplicate type names.

The type foo is defined multiple times with different meanings, which can lead to confusion. Consider using more descriptive and unique names for each type.

- type foo = foo[string] & typeof foo;
- interface foo extends (typeof foo) {
+ type FooType = foo[string] & typeof foo;
+ interface FooInterface extends (typeof foo) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type foo = foo[string] & typeof foo;
// ^inlayHint: "props."
interface foo extends (typeof foo) {
// ^inlayHint: "props."
foo: string;
foo(foo: string): void;
foo: (foo: string) => void;
}
type FooType = foo[string] & typeof foo;
// ^inlayHint: "props."
interface FooInterface extends (typeof foo) {
// ^inlayHint: "props."
foo: string;
foo(foo: string): void;
foo: (foo: string) => void;
}

Comment on lines +276 to +280
// TODO: more conditions
function isReferencedIdentifier(
id: ts.Identifier,
parent: ts.Node | null
) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand conditions in isReferencedIdentifier.

The TODO comment suggests more conditions are needed. Ensure all necessary conditions are covered to avoid false positives in identifier referencing.

Would you like assistance in identifying additional conditions for isReferencedIdentifier?

Comment on lines +19 to +23
const settings: Record<string, boolean> = {};
const result: vscode.InlayHint[] = [];
const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri));
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for undefined decoded or sourceScript.

The code assumes decoded and sourceScript are defined without checks. Add checks to handle cases where they might be undefined.

- const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri));
- const sourceScript = decoded && context.language.scripts.get(decoded[0]);
- const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
+ const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri));
+ if (!decoded) return [];
+ const sourceScript = context.language.scripts.get(decoded[0]);
+ if (!sourceScript) return [];
+ const virtualCode = sourceScript.generated?.embeddedCodes.get(decoded[1]);
+ if (!virtualCode) return [];
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const settings: Record<string, boolean> = {};
const result: vscode.InlayHint[] = [];
const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri));
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
const settings: Record<string, boolean> = {};
const result: vscode.InlayHint[] = [];
const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri));
if (!decoded) return [];
const sourceScript = context.language.scripts.get(decoded[0]);
if (!sourceScript) return [];
const virtualCode = sourceScript.generated?.embeddedCodes.get(decoded[1]);
if (!virtualCode) return [];

Comment on lines +64 to +68
settings[hint.setting] ??= await context.env.getConfiguration?.<boolean>(hint.setting) ?? false;

if (!settings[hint.setting]) {
continue;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using optional chaining with non-null assertions.

The use of optional chaining with non-null assertions can lead to confusing code. Consider restructuring to avoid this pattern.

- settings[hint.setting] ??= await context.env.getConfiguration?.<boolean>(hint.setting) ?? false;
+ if (!(hint.setting in settings)) {
+   settings[hint.setting] = await context.env.getConfiguration?.<boolean>(hint.setting) ?? false;
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
settings[hint.setting] ??= await context.env.getConfiguration?.<boolean>(hint.setting) ?? false;
if (!settings[hint.setting]) {
continue;
}
if (!(hint.setting in settings)) {
settings[hint.setting] = await context.env.getConfiguration?.<boolean>(hint.setting) ?? false;
}
if (!settings[hint.setting]) {
continue;
}

Comment on lines +25 to +47
if (virtualCode instanceof VueVirtualCode) {

const codegen = tsCodegen.get(virtualCode.sfc);
const inlayHints = [
...codegen?.generatedTemplate()?.inlayHints ?? [],
...codegen?.generatedScript()?.inlayHints ?? [],
];
const scriptSetupRanges = codegen?.scriptSetupRanges();

if (scriptSetupRanges?.props.destructured && virtualCode.sfc.scriptSetup?.ast) {
for (const [prop, isShorthand] of findDestructuredProps(ts, virtualCode.sfc.scriptSetup.ast, scriptSetupRanges.props.destructured)) {
const name = prop.text;
const end = prop.getEnd();
const pos = isShorthand ? end : end - name.length;
const label = isShorthand ? `: props.${name}` : 'props.';
inlayHints.push({
blockName: 'scriptSetup',
offset: pos,
setting: 'vue.inlayHints.destructuredProps',
label,
});
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify destructured props handling.

The logic for handling destructured props could be simplified by checking for virtualCode earlier and avoiding nested if statements.

- if (virtualCode instanceof VueVirtualCode) {
+ if (!(virtualCode instanceof VueVirtualCode)) return result;

- if (scriptSetupRanges?.props.destructured && virtualCode.sfc.scriptSetup?.ast) {
+ if (!scriptSetupRanges?.props.destructured || !virtualCode.sfc.scriptSetup?.ast) return result;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (virtualCode instanceof VueVirtualCode) {
const codegen = tsCodegen.get(virtualCode.sfc);
const inlayHints = [
...codegen?.generatedTemplate()?.inlayHints ?? [],
...codegen?.generatedScript()?.inlayHints ?? [],
];
const scriptSetupRanges = codegen?.scriptSetupRanges();
if (scriptSetupRanges?.props.destructured && virtualCode.sfc.scriptSetup?.ast) {
for (const [prop, isShorthand] of findDestructuredProps(ts, virtualCode.sfc.scriptSetup.ast, scriptSetupRanges.props.destructured)) {
const name = prop.text;
const end = prop.getEnd();
const pos = isShorthand ? end : end - name.length;
const label = isShorthand ? `: props.${name}` : 'props.';
inlayHints.push({
blockName: 'scriptSetup',
offset: pos,
setting: 'vue.inlayHints.destructuredProps',
label,
});
}
}
if (!(virtualCode instanceof VueVirtualCode)) return result;
const codegen = tsCodegen.get(virtualCode.sfc);
const inlayHints = [
...codegen?.generatedTemplate()?.inlayHints ?? [],
...codegen?.generatedScript()?.inlayHints ?? [],
];
const scriptSetupRanges = codegen?.scriptSetupRanges();
if (!scriptSetupRanges?.props.destructured || !virtualCode.sfc.scriptSetup?.ast) return result;
for (const [prop, isShorthand] of findDestructuredProps(ts, virtualCode.sfc.scriptSetup.ast, scriptSetupRanges.props.destructured)) {
const name = prop.text;
const end = prop.getEnd();
const pos = isShorthand ? end : end - name.length;
const label = isShorthand ? `: props.${name}` : 'props.';
inlayHints.push({
blockName: 'scriptSetup',
offset: pos,
setting: 'vue.inlayHints.destructuredProps',
label,
});
}

@pull pull bot merged commit 0f14cde into so1ve:master Aug 10, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants