Skip to content

ERRORs super visible now. Updated Completions, Code re-organization, UDT fields, Vars. #26

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

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

kaigouthro
Copy link
Contributor

This pull request introduces several changes to the PineScript extension, focusing on improving code completion, refactoring imports, and updating the configuration in package.json. The most significant updates include enhancements to completion item handling, new functionality for user-defined types (UDTs), and adjustments to menu configurations.

Code Completion Enhancements:

  • Refactored determineCompletionItemKind method: Added a docDetails parameter to provide more context when determining completion item kinds, including support for additional types like EnumMember and Literal String. [1] [2] [3]
  • Introduced new completion methods: Added instanceFieldCompletions for UDT instance fields and udtConstructorCompletions for UDT constructors, enhancing the ability to suggest relevant completions for user-defined types. [1] [2]
  • Improved inline argument completions: Enhanced logic to provide better suggestions for arguments, including handling empty slots, partially typed arguments, and values for specific fields.

Refactoring and Code Organization:

  • Split imports for clarity: Moved PineInlineCompletionContext to a separate file, improving modularity and readability of imports in src/PineClass.ts.
  • Updated PineDocString class: Added a new regex pattern to match enum declarations, enabling better parsing of enums.

Configuration Updates:

  • Simplified submenu definitions in package.json: Removed the pine.mysubmenu2 submenu and updated related menu configurations to streamline the extension's context menu structure. [1] [2]

These changes collectively enhance the extension's functionality, maintainability, and user experience.

kaigouthro and others added 24 commits May 18, 2025 13:01
I've implemented comprehensive inline completion and signature help for your user-defined functions, User-Defined Types (UDTs), and enums.

Key enhancements include:

1.  **User-Defined Functions:**
    *   Accurate parsing of function names, parameters (including types and default values), docstrings (`@function`, `@param`), and export/method keywords.
    *   Correct suggestion of your function names.
    *   Detailed signature help for your functions, displaying parameters, types, defaults, and descriptions from `@param` tags.
    *   Argument completion for your function parameters, including type-appropriate variable suggestions.

2.  **User-Defined Types (UDTs):**
    *   Reliable parsing of UDT names, fields (name, type, default value, `const` status), docstrings (`@type`, `@field`), and export keywords.
    *   Completion suggestion for your UDT names.
    *   Suggestion of `.new()` constructor for UDTs.
    *   Detailed signature help for UDT constructors, showing all fields, their types, default values, and descriptions from `@field` tags.
    *   Argument completion for UDT constructor fields.
    *   Instance field completion: When typing `myUdtInstance.`, fields of `myUdtInstance` are suggested with their types, documentation, and default values.

3.  **Enums:**
    *   Your user-defined enums (conventionally UDTs with `const` fields) are supported.
    *   Enum member names are suggested with an `EnumMember` kind when accessing them (e.g., `MyEnum.MEMBER_A`).
    *   Built-in constant namespaces (e.g., `color.`) also provide `EnumMember` completions.
    *   Documentation for enum members shows their values.

These changes significantly improve your development experience by providing more intelligent and context-aware assistance when working with user-defined code structures in Pine Script.
feat: Enhance completions for user-defined constructs
This commit addresses your feedback regarding inline completions for User-Defined Type (UDT) constructors. Specifically, it ensures that field names (e.g., `fieldname =`) are properly suggested inline and that value suggestions are contextually appropriate.

Enhancements:
- Modified `PineInlineCompletionContext.argumentInlineCompletions` to more intelligently select and prioritize inline suggestions:
    - Suggests the next available field name (e.g., `fieldname=`) when the argument slot is empty or after a comma.
    - Offers relevant value suggestions (including type-matched variables and newly added generic literals like `""`, `0`, `na`, `true`, `false`) after a field name and `=` are typed.
- Improved `PineInlineCompletionContext.createInlineCompletionItem` to correctly calculate `insertText` and `Range` for a smoother inline completion experience.
- Refined `PineCompletionProvider.argumentCompletions` to ensure consistent `CompletionItemKind` for UDT field parameters.
- Verified that `PineSignatureHelpProvider` correctly populates `PineSharedCompletionState` to support these refined UDT constructor argument suggestions.
- Removed premature clearing of completion state in `PineInlineCompletionContext` to allow you to trigger standard completions if an inline suggestion is ignored.

These changes result in a more intuitive and complete suggestion experience when working with UDT constructors, aligning with the behavior of built-in function calls.
fix: Refine UDT constructor inline argument suggestions
This commit introduces several improvements to the Pine Script VS Code extension:

1.  **Context Menu Refactoring:**
    - Simplified the editor context menu contributions in `package.json`.
    - Removed nested submenus for Pine Script commands, directly adding them to the `editor/context` group for a cleaner user experience.
    - Ensured commands like "Typify Variables" and "Generate Docstring" correctly use `when` clauses for visibility.

2.  **"Generate Docstring" Feature Enhancements:**
    - Added support for generating docstrings for `enum` declarations.
    - Updated the output format for both `type` (UDT) and `enum` docstrings based on your feedback, including `@type`, `@field`, and `@enum` tags with detailed type information and default values where applicable.

3.  **"Typify Variables" Feature Improvements:**
    - Significantly refactored the type inference logic in `PineTypify.ts`.
    - Variables can now have their types inferred from their assignment values, including:
        - String literals (including `str.format()`).
        - Number literals (int, float, scientific notation).
        - Color literals and functions (hex, `color.rgb()`, `color.new()`, named colors).
        - Boolean literals (`true`, `false`).
        - The `na` value.
        - Ternary expressions, including those involving `na`.
    - Improved reliability by checking for already-typed variables to prevent incorrect re-typing.
    - Enhanced `makeMap` to include built-in constants (`true`, `false`, `na`, common colors) for better type resolution.

4.  **Architectural Exploration (Preliminary):**
    - Investigated refactoring `VSCode.ts` and `PineClass.ts` to reduce custom abstractions and align more closely with native VS Code APIs, paving the way for future developments like a robust linter/formatter.

These changes address your feedback to improve the usability and functionality of core editing assistance features.
…provements

feat: Enhance Docstring, Typify, and Context Menus
This commit addresses several issues:

1.  Removes a large block of commented-out code in `src/PineInlineCompletionContext.ts` to improve maintainability.
2.  Integrates `PineCompletionService.ts` into `PineCompletionProvider.ts` and `PineSignatureHelpProvider.ts`. These providers now use the service for fetching completion and signature help documentation, centralizing the logic.
3.  Consolidates duplicate `onDidChangeTextDocument` listeners in `extension.ts`. This prevents `PineLint.handleDocumentChange` from being triggered twice on document changes, ensuring linting occurs only once per relevant change.

The integration of `PineCompletionService` in the providers primarily affects how they retrieve documentation for functions, methods, and UDTs. The core logic for argument completion suggestions within `PineSignatureHelpProvider` (specifically the `sendCompletions` and `extractCompletions` methods) and its usage by `PineCompletionProvider` remains largely unchanged in this refactoring pass to minimize risk, but the foundation for future improvements is now in place.
This commit builds upon the previous refactoring by:

1.  Removing Obsolete Code:
    - Deleted commented-out methods (`determineFunctionType`, `extractMethodString`) in `PineSignatureHelpProvider.ts`.
    - Removed unused imports in `PineInlineCompletionContext.ts`.

2.  Improving Type Safety:
    - Updated `PineCompletionProvider.ts` to use the `CompletionDoc` interface for parameters and variables handling data from `PineCompletionService`, enhancing type safety in `createCompletionItem`.

3.  Implementing Shared `PineCompletionService` Singleton:
    - Instantiated `PineCompletionService` as a singleton (`Class.pineCompletionService`) in `extension.ts`.
    - Modified `PineCompletionProvider.ts` and `PineSignatureHelpProvider.ts` to use this shared instance instead of creating their own, reducing redundancy and ensuring consistent state.
    - Added the `pineCompletionService` static member to `PineClass.ts`.

These changes further improve code maintainability, type safety, and resource management within the extension.
…tor-providers

Refactor: Consolidate listeners and integrate CompletionService
This commit introduces enhanced visibility for errors and warnings within the Pine Script editor by:

- Highlighting the background of lines containing errors or warnings.
- Adding distinct gutter icons for error and warning lines.

These changes are themeable through new color contributions in `package.json`:
- `pine.errorBackground`
- `pine.warningBackground`
- `pine.errorGutterIcon` (for future use, icons currently use SVG-defined colors)
- `pine.warningGutterIcon` (for future use, icons currently use SVG-defined colors)

The implementation involves:
- Defining new `TextEditorDecorationType`s in `src/extension.ts` for errors and warnings.
- Updating `src/PineLint.ts` to apply these decorations based on diagnostic severity.
- Adding new SVG icons for the gutter indicators.
feat: Improve error and warning visibility
@kaigouthro kaigouthro changed the title Updated Completions, Code re-organization, UDT fields, Vars. ERRORs super visible now. Updated Completions, Code re-organization, UDT fields, Vars. Jun 2, 2025
@kaigouthro
Copy link
Contributor Author

Merge this, publish it. k?

it's big improved. tested, works very well.

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.

1 participant