Skip to content

Commit 4b4f372

Browse files
authored
Merge pull request yankikucuk#6 from yankikucuk/fix/audit-3-4-0
Release 3.4.0: audit fixes
2 parents 40c2324 + 55cb5d6 commit 4b4f372

41 files changed

Lines changed: 454 additions & 85 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/CONTRIBUTING.md‎

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contributing
22

3-
Thanks for helping keep Pine Script highlighting accurate. This document covers the workflow; the README explains how the grammar is put together.
3+
Thanks for helping keep Pine Script support accurate. This document covers the workflow; the README explains what the extension does and how the pieces fit together.
44

55
## Setup
66

@@ -15,23 +15,30 @@ Node 20 or newer is required.
1515

1616
## Where things live
1717

18-
| Change you want to make | Edit this |
19-
| --------------------------------------- | --------------------------------------------------------------------------------------------------------- |
20-
| Add or remove a built-in function | `src/data/functions.json` |
21-
| Add or remove a built-in variable | `src/data/variables.json` |
22-
| Add or remove a built-in constant | `src/data/constants.json` |
23-
| Add a compiler annotation (`//@...`) | `src/data/annotations.json` |
24-
| Add a keyword, type or change a scope | `src/grammar.mjs` |
25-
| Change folding, brackets or indentation | `language-configuration.json` |
26-
| Add a snippet | `snippets/pinescript.code-snippets` |
27-
| Completion, hover, commands, inference | `src/extension/core/*` (logic) and `src/extension/providers/*`, `src/extension/commands/*` (VS Code glue) |
28-
| Change a theme color | `themes/*.json` |
29-
| Never | `syntaxes/pinescript.tmLanguage.json`, `src/data/reference.json`, `dist/` (generated) |
18+
| Change you want to make | Edit this |
19+
| --------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
20+
| Add or remove a built-in function | `src/data/functions.json` |
21+
| Add or remove a built-in variable | `src/data/variables.json` |
22+
| Add or remove a built-in constant | `src/data/constants.json` |
23+
| Add a compiler annotation (`//@...`) | `src/data/annotations.json` |
24+
| Add a keyword, type or change a scope | `src/grammar.mjs` |
25+
| Change folding, brackets or indentation | `language-configuration.json` |
26+
| Add a snippet | `snippets/pinescript.code-snippets` |
27+
| Completion, hover, commands, inference | `src/extension/core/*` (logic) and `src/extension/providers/*`, `src/extension/commands/*` (VS Code glue) |
28+
| Change how a document is formatted | `src/extension/core/formatter.ts` |
29+
| Add or change an offline rule | `src/extension/core/lint.ts`, and list the rule in the `pinescript.lint.disabledRules` enum in `package.json` |
30+
| Change a quick fix | `src/extension/core/quick-fix.ts` |
31+
| Definition, references, rename | `src/extension/core/symbols.ts` |
32+
| Colour swatches, semantic tokens | `src/extension/core/colors.ts`, `src/extension/core/semantic.ts` |
33+
| Change a theme color | `themes/*.json` (`tokenColors` for the grammar, `semanticTokenColors` for declared names) |
34+
| Never | `syntaxes/pinescript.tmLanguage.json`, `src/data/reference.json`, `dist/` (generated) |
3035

3136
The data files are grouped by namespace. A function `ta.sma` goes under the `"ta"` key as `"sma"`. Identifiers without a namespace go under the `""` key. Nested namespaces such as `strategy.closedtrades` are their own key.
3237

3338
`src/extension/core` never imports `vscode`; that is what makes it testable with vitest. Providers and commands only translate between VS Code types and core types.
3439

40+
Everything a provider needs from a document goes through `analyze()` in `src/extension/vscode/document-cache.ts`, which parses each document once per version. Anything that walks every identifier of a file should go through `sourceIndex()` in `src/extension/core/symbols.ts` rather than rescanning the token stream: that is what keeps the offline checks linear instead of quadratic on long scripts.
41+
3542
## Working on the extension
3643

3744
```sh
@@ -68,18 +75,22 @@ Built-in identifiers come from the [Pine Script v6 reference](https://www.tradin
6875
## Manual checklist before a release
6976

7077
- Completion after `ta.`, inside `plot(`, after `//@`, after `import `
71-
- Hover on `close`, `ta.sma`, a user function, an import line
78+
- Hover on `close`, `ta.sma`, a user function, a function parameter, an import line
7279
- Signature help through all parameters of `plot(`
73-
- Outline shows functions, types, enums, variables
80+
- Outline shows functions, types with fields, enums with members, top-level variables
81+
- Go to Definition, Find All References and Rename on a user function, a variable and an enum member
82+
- Format Document on a file with two space indentation and on one with wrapped calls
83+
- Colour swatch and picker on `#FF9800`, `color.red` and `color.new(color.blue, 25)`
84+
- Offline checks flag an old pragma and a bare `sma`; Convert to v6 fixes them
7485
- Generate Docstring on a function, a type and an enum
75-
- Add Type Annotations on `tests/snapshots/strategy-v6.pine`
76-
- Both themes on `tests/snapshots/strategy-v6.pine`
77-
- With `pinescript.diagnostics.remote` on: an undeclared identifier is underlined
86+
- Add Type Annotations on `tests/snapshots/strategy-v6.pine` and on `var a = 1`
87+
- Both themes on `tests/snapshots/strategy-v6.pine`, with semantic highlighting on
88+
- With `pinescript.diagnostics.remote` on: an undeclared identifier is underlined and the lightbulb offers a fix
7889

7990
## Releasing
8091

8192
Maintainers only.
8293

8394
1. Update `CHANGELOG.md` and bump `version` in `package.json`.
84-
2. Commit, then tag: `git tag v3.x.y && git push --tags`.
95+
2. Commit, then tag: `git tag -a v3.x.y -m 3.x.y && git push origin v3.x.y`.
8596
3. The release workflow builds the `.vsix`, attaches it to a GitHub release and publishes to the Marketplace when the `VSCE_PAT` secret is configured.

‎CHANGELOG.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
55

66
## [Unreleased]
77

8+
## [3.4.0] - 2026-09-08
9+
10+
A review pass over the whole extension: three defects that produced wrong output, a large performance
11+
fix, and documentation for every exported declaration.
12+
13+
### Fixed
14+
15+
- **Add Type Annotations wrote broken code.** A declaration's column was found by searching the raw line for its name, so `var a = 1` reported column 1 and the command produced `vint ar a = 1`. Columns now come from the tokens. The same column is used by Go to Definition and Rename, which were off by the same amount.
16+
- **A `for` counter was recorded with `for` as its type**, so a value read from it was annotated `for x = i`. Counters are now typed `int`, and `for x in`, `for [index, element] in` declare their names too. All three are scoped to the loop block rather than the rest of the file.
17+
- **The Outline pointed at the wrong lines** for the fields of a type or the members of an enum whenever a comment or a blank line sat between them; every entry was off by one per interleaved line. Fields and members now carry the line they are written on.
18+
- Range formatting on a document with Windows line endings never recognised that nothing had changed, and returned an edit anyway.
19+
20+
### Changed
21+
22+
- The offline checks are 51 times faster on a long script: 160 ms to 3 ms on a 1,500 line document, and now linear rather than quadratic. Semantic highlighting on the same file went from 13 ms to 2 ms. Both used to rescan the token stream for every symbol they looked at; they share one index per document version now.
23+
- Hovering a function parameter shows its declaration and its `//@param` text instead of nothing.
24+
- The Outline lists the declarations at the top level of a script and no longer mixes in variables declared inside blocks.
25+
26+
### Documentation
27+
28+
- Every exported function, class, interface and type in `src/extension` now carries a comment saying what it is for and what its contract is, rather than only the ones with surprising behaviour.
29+
- `CONTRIBUTING.md` covers the formatter, the offline rules, navigation, colours and semantic tokens, and explains where a change that walks every identifier belongs.
30+
831
## [3.3.0] - 2026-09-08
932

1033
### Added

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "pine-script-syntax-highlighter",
33
"displayName": "Pine Script Syntax Highlighter",
44
"description": "Pine Script v6 for Visual Studio Code: highlighting, completion, hover documentation, signature help, snippets, themes and compiler diagnostics.",
5-
"version": "3.3.0",
5+
"version": "3.4.0",
66
"publisher": "ex-codes",
77
"author": {
88
"name": "Yankı Küçük",

‎src/extension/commands/add-type-annotations.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { loadReference } from '../core/reference';
33
import { planTypeAnnotations } from '../core/type-inference';
44
import { analyze } from '../vscode/document-cache';
55

6+
/** The types the compiler last reported for a document, when diagnostics are on. */
67
export type CompilerTypesLookup = (uri: vscode.Uri) => ReadonlyMap<string, string> | undefined;
78

9+
/** Registers the command that prefixes untyped declarations with their inferred type. */
810
export function registerAddTypeAnnotations(context: vscode.ExtensionContext, compilerTypes: CompilerTypesLookup): void {
911
context.subscriptions.push(
1012
vscode.commands.registerCommand('pinescript.addTypeAnnotations', async () => {

‎src/extension/commands/convert-to-v6.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { analyze } from '../vscode/document-cache';
77
/** The rules whose fixes together move a script from an older Pine version to the current one. */
88
const MIGRATION_RULES = new Set(['missing-version', 'old-version', 'legacy-name', 'unknown-argument']);
99

10+
/** Registers the command that applies every migration fix in a document at once. */
1011
export function registerConvertToV6(context: vscode.ExtensionContext, ref: ReferenceIndex): void {
1112
context.subscriptions.push(
1213
vscode.commands.registerCommand('pinescript.convertToV6', async () => {

‎src/extension/commands/generate-docstring.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { annotationBlockRange, docstringLines } from '../core/docstring';
33
import { declarationAt, type DeclSymbol } from '../core/document-model';
44
import { analyze } from '../vscode/document-cache';
55

6+
/** The edit that writes, or completes, the `//@` block for one declaration. */
67
export function docstringEdit(document: vscode.TextDocument, symbol: DeclSymbol): vscode.TextEdit {
78
const { lines } = analyze(document);
89
const indent = lines[symbol.line]!.match(/^\s*/)![0];
@@ -14,6 +15,7 @@ export function docstringEdit(document: vscode.TextDocument, symbol: DeclSymbol)
1415
: vscode.TextEdit.insert(new vscode.Position(symbol.line, 0), text);
1516
}
1617

18+
/** Registers the command and its lightbulb action for documenting a declaration. */
1719
export function registerGenerateDocstring(context: vscode.ExtensionContext): void {
1820
context.subscriptions.push(
1921
vscode.commands.registerCommand('pinescript.generateDocstring', async (line?: number) => {

‎src/extension/commands/new-file.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const TITLES: Record<TemplateKind, string> = {
88
};
99
const LABELS: Record<TemplateKind, string> = { indicator: 'Indicator', strategy: 'Strategy', library: 'Library' };
1010

11+
/** Registers the three commands that open a new script from a template. */
1112
export function registerNewFileCommands(context: vscode.ExtensionContext): void {
1213
for (const kind of ['indicator', 'strategy', 'library'] as const) {
1314
context.subscriptions.push(

‎src/extension/commands/open-reference.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode';
22
import { REFERENCE_URL, loadReference } from '../core/reference';
33
import { wordAt } from '../core/tokenizer';
44

5+
/** Registers the command that opens the reference at the built-in under the cursor. */
56
export function registerOpenReference(context: vscode.ExtensionContext): void {
67
context.subscriptions.push(
78
vscode.commands.registerCommand('pinescript.openReference', async () => {

‎src/extension/core/call-resolver.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Token, TokenizedLine } from './tokenizer';
22

3+
/** The call the cursor sits inside, and which argument it is on. */
34
export interface CallInfo {
45
name: string;
56
argIndex: number;
@@ -28,6 +29,10 @@ function tokensBefore(tokenLines: TokenizedLine[], line: number, col: number): T
2829
return out;
2930
}
3031

32+
/**
33+
* Finds the innermost call the cursor is inside, looking back over wrapped lines. Grouping
34+
* parentheses and index brackets are stepped over, so their commas do not count as arguments.
35+
*/
3136
export function enclosingCall(tokenLines: TokenizedLine[], line: number, col: number): CallInfo | null {
3237
const tokens = tokensBefore(tokenLines, line, col);
3338
let depth = 0;

‎src/extension/core/colors.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface Rgba {
99
alpha: number;
1010
}
1111

12+
/** One colour found in the document, and the range the picker should replace. */
1213
export interface ColorSpot {
1314
line: number;
1415
startCol: number;

0 commit comments

Comments
 (0)