Support type hint directives and other record field intellisense improvements#277
Support type hint directives and other record field intellisense improvements#277mattmasson wants to merge 9 commits into
Conversation
…uage-services into improvement/m-type-hint-directives
There was a problem hiding this comment.
Pull request overview
Adds opt-in (isTypeDirectiveAllowed) language-service support for /// @type ... directives and uses the resolved directive types to improve inspection results, hover text, signature help, and record-field completions (including “current record” suggestions and recovery for incomplete records).
Changes:
- Introduces
isTypeDirectiveAllowedinInspectionSettings(default intended to be off) and threads it through inspection/type-resolution. - Extends scope items (let variables, record fields, section members) with optional
typeDirectivemetadata and applies directive-derived types during inspection. - Enhances local document provider autocomplete/hover/signature help to leverage directive-resolved types, including current-record field suggestions with duplicate filtering and dangling-comma recovery, plus adds targeted tests.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/powerquery-language-services/inspectionSettings.ts | Adds isTypeDirectiveAllowed to the public inspection settings surface. |
| src/powerquery-language-services/inspectionUtils.ts | Normalizes inspection settings and defaults directive flag behavior. |
| src/powerquery-language-services/inspection/type/inspectType/inspectTypeState/inspectTypeStateUtils.ts | Threads directive flag through inspect-type state conversions. |
| src/powerquery-language-services/inspection/type/inspectType/common.ts | Resolves and applies @type directives during scope-item type inspection. |
| src/powerquery-language-services/inspection/scope/scope.ts | Extends scope-item model with typeDirective metadata. |
| src/powerquery-language-services/inspection/scope/scopeInspection.ts | Captures parser-attached type directives and attaches them to scope items. |
| src/powerquery-language-services/providers/commonTypes.ts | Expands provider contexts to include parse state / inspection settings where needed. |
| src/powerquery-language-services/providers/localDocumentProvider/localDocumentProvider.ts | Adds directive-backed hover formatting and current-record field completion logic (plus recovery). |
| src/powerquery-language-services/inspection/autocomplete/autocompleteFieldAccess.ts | Extends allowed record-like type kinds for field-access completions. |
| src/powerquery-language-services/inspection/invokeExpression/invokeExpression.ts | Updates function-type handling to use FunctionSignature checks. |
| src/powerquery-language-services/analysis/analysisBase.ts | Plumbs parse state and inspection settings into autocomplete provider context. |
| src/test/inspection/typeDirective.test.ts | New focused tests for directive resolution/apply behavior (enabled/disabled + strategies). |
| src/test/providers/localDocumentProvider.test.ts | Tests directive-backed current-record completions, hover, and signature help. |
| src/test/testConstants.ts | Sets directive flag default to false in test constants. |
| src/test/inspection/type.test.ts | Updates inspection settings literals to include directive flag default false. |
| src/test/inspection/scope.test.ts | Updates inspection settings literals to include directive flag default false. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…uage-services into improvement/m-type-hint-directives
…uage-services into improvement/m-type-hint-directives
|
@copilot review again and resolve previous comments that were fixed. |
All six reviewer comments have been addressed in commit
|
|
Moving back to Draft - I'm going to try to redo this change. |
Summary
Adds language-service support for
/// @type ...directives on local bindings and uses those hints to improve type inspection, hover, and record-field completions.This PR builds on parser-level directive attachment and teaches
powerquery-language-servicesto resolve directive payloads from local scope, library symbols, or inline type text. The feature remains opt-in behindisTypeDirectiveAllowed.What Changed
isTypeDirectiveAllowedto inspection settings and kept it disabled by default.typeDirectivemetadata./// @type [ Foo = text ]/// @type Resource.TypeWhy
The broader type-hint feature needs language services to treat parser-attached
@typemetadata as real type information. Without this layer, the parser can discover directives, but completions, hover, and type inspection still behave as if the hint does not exist.This PR wires that directive metadata into the existing inspection flow instead of introducing protocol changes or completion-only special cases.
Resolution Behavior
When
isTypeDirectiveAllowedis enabled, directive payloads are resolved in this order:externalTypeResolverThat allows all of the following patterns:
Current-Record Completion Behavior
This PR adds a current-record completion path for directive-backed record/table-like types, including:
For malformed record states where parser recovery drops directive attachment on the AST node, the local document provider falls back to the preserved lexer comments so completions still work while the user is mid-edit.
Tests
Added focused tests for:
Key test files:
Validation
Reviewer Notes