Skip to content

Commit 556c9f8

Browse files
authored
Merge pull request #15 from kaigouthro/main
Updated v6 + syntax + theme + md code block hillites this time tested >.< .. works
2 parents 73c1946 + 511e9fa commit 556c9f8

34 files changed

+3460
-934
lines changed

package.json

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "git",
88
"url": "https://github.com/FFriZ/Pine-Script-v5-VS-Code"
99
},
10-
"version": "0.1.7",
10+
"version": "0.1.8",
1111
"type": "commonjs",
1212
"engines": {
1313
"vscode": "^1.93.0",
@@ -62,6 +62,12 @@
6262
"uiTheme": "vs-dark",
6363
"path": "themes/Pine-Original.json"
6464
},
65+
{
66+
"label": "Pine-V4-Classic",
67+
"id": "Dark V4 Theme (Deep Coverage)",
68+
"uiTheme": "vs-dark",
69+
"path": "themes/Pine-classic-v4.json"
70+
},
6571
{
6672
"label": "Pine-Basic",
6773
"id": "Dark Theme (Basic)",
@@ -312,7 +318,14 @@
312318
{
313319
"language": "pine",
314320
"scopeName": "source.pine",
315-
"path": "themes/pine.tmLanguage.json"
321+
"path": "syntaxes/pine.tmLanguage.json"
322+
},
323+
{
324+
"scopeName": "source.markdown",
325+
"path": "syntaxes/pine-embedded.tmLanguage.json",
326+
"injectTo": [
327+
"text.html.markdown"
328+
]
316329
}
317330
]
318331
},
@@ -343,7 +356,7 @@
343356
"ts-loader": "^9.5.1",
344357
"type-coverage": "^2.0.0",
345358
"typedoc": "^0.26.7",
346-
"typescript": "^5.6.2",
359+
"typescript": "^5.7.3",
347360
"webpack": "^5.94.0",
348361
"webpack-cli": "^5.1.4",
349362
"xo": "^0.54.0"

src/PineClass.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { PineUserInputs } from './PineUserInputs'
77
import { PineHoverProvider } from './PineHoverProvider/PineHoverProvider'
88
import { PineLibCompletionProvider } from './PineLibCompletionProvider'
99
import { PineLibHoverProvider } from './PineLibHoverProvider'
10-
import { PineInlineCompletionContext, PineCompletionProvider } from './PineCompletionProvider'
10+
import { PineInlineCompletionHandler, PineCompletionProvider } from './PineCompletionProvider'
1111
import { PineFormatResponse } from './PineFormatResponse'
1212
import { PineScriptList } from './PineScriptList'
1313
import { PineTemplates } from './PineTemplates'
@@ -28,7 +28,7 @@ export class Class {
2828
public static pineLibHoverProvider: PineLibHoverProvider
2929
public static pineLibCompletionProvider: PineLibCompletionProvider
3030
public static pineSignatureHelpProvider: PineSignatureHelpProvider
31-
public static pineInlineCompletionContext: PineInlineCompletionContext
31+
public static pineInlineCompletionContext: PineInlineCompletionHandler
3232
public static pineCompletionProvider: PineCompletionProvider
3333
public static pineColorProvider: PineColorProvider
3434
public static pineScriptList: PineScriptList
@@ -131,7 +131,7 @@ export class Class {
131131
* Lazy loads and returns an instance of PineInlineCompletionContext.
132132
* @returns {PineInlineCompletionContext} The PineInlineCompletionContext instance.
133133
*/
134-
static get PineInlineCompletionContext(): PineInlineCompletionContext {
134+
static get PineInlineCompletionContext(): PineInlineCompletionHandler {
135135
if (!Class.pineInlineCompletionContext) {
136136
Class.PineCompletionSignatureInitOrder()
137137
}
@@ -148,7 +148,7 @@ export class Class {
148148
}
149149
if (!Class.pineCompletionProvider) {
150150
// console.log('PineCompletionProvider initializing')
151-
Class.pineInlineCompletionContext = new PineInlineCompletionContext()
151+
Class.pineInlineCompletionContext = new PineInlineCompletionHandler()
152152
Class.pineCompletionProvider = new PineCompletionProvider()
153153
}
154154
}

src/PineColorProvider.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class PineColorProvider implements vscode.DocumentColorProvider {
9494
this.findColors(text, document, this.regexColorNew),
9595
this.findColors(text, document, this.regexColorRgb),
9696
]
97-
97+
9898
// Add all found colors to the colorInfos array
9999
findColors.forEach((result): any => colorInfos.push(...result))
100100
return colorInfos
@@ -121,11 +121,11 @@ export class PineColorProvider implements vscode.DocumentColorProvider {
121121
const range = this.extractRange(document, match.index, colorString)
122122

123123
// Skip if the color is within a comment
124-
if (this.isWithinComment(document, range.start)) {continue}
124+
if (this.isWithinComment(document, range.start)) { continue }
125125

126126
// Parse the color string and add it to the colorInfos array
127127
const color = this.parseColorString(colorString)
128-
if (!color) {continue}
128+
if (!color) { continue }
129129
colorInfos.push(new vscode.ColorInformation(range, color))
130130
}
131131
return colorInfos
@@ -178,17 +178,17 @@ export class PineColorProvider implements vscode.DocumentColorProvider {
178178
// Subtract from 1 and divide by 100 to normalize to 0-1 range
179179
return 1 - alpha / 100
180180
}
181-
181+
182182
/**
183183
* Denormalizes an alpha value from the 0-1 range to the 0-100 range.
184184
* @param alpha - The alpha value to denormalize.
185185
* @returns The denormalized alpha value.
186186
*/
187187
private denormalizeAlpha(alpha: number) {
188188
// Subtract from 1, multiply by 100 and round to denormalize to 0-100 range
189-
return 100 - Math.round(100 * alpha)
189+
return 100 - Math.round(100 * alpha)
190190
}
191-
191+
192192
/**
193193
* Converts a number to a hex string.
194194
* @param color - The number to convert.
@@ -213,9 +213,9 @@ export class PineColorProvider implements vscode.DocumentColorProvider {
213213
const g = this.hexFromNumber(color.green);
214214
const b = this.hexFromNumber(color.blue);
215215
const alphaHex = this.hexFromNumber(color.alpha); // Convert alpha for standard RGBA format
216-
216+
217217
let hexColor = `#${r}${g}${b}`;
218-
218+
219219
if (includeAlphaOrLiteral === 'alpha' && color.alpha !== 1) {
220220
return `${hexColor}${alphaHex}`; // Append alpha in hex if not fully visible
221221
} else if (includeAlphaOrLiteral === 'literal') {
@@ -226,7 +226,7 @@ export class PineColorProvider implements vscode.DocumentColorProvider {
226226
}
227227
return hexColor;
228228
}
229-
229+
230230
/**
231231
* Gets the literal color name for a given hex color.
232232
* @param hexColor - The hex color to get the literal color name for.
@@ -240,7 +240,7 @@ export class PineColorProvider implements vscode.DocumentColorProvider {
240240
}
241241
return null
242242
}
243-
243+
244244
/**
245245
* Converts a vscode.Color object to an RGB color string.
246246
* @param color - The vscode.Color object to convert.
@@ -256,7 +256,7 @@ export class PineColorProvider implements vscode.DocumentColorProvider {
256256
const a = this.denormalizeAlpha(color.alpha)
257257
return `color.rgb(${r}, ${g}, ${b}, ${a})`
258258
}
259-
259+
260260
/**
261261
* Converts a vscode.Color object to a new color string.
262262
* @param color - The vscode.Color object to convert.
@@ -266,7 +266,7 @@ export class PineColorProvider implements vscode.DocumentColorProvider {
266266
const hexColor = this.colorHexPresentation(color, 'noAlpha')
267267
return `color.new(${hexColor}, ${this.denormalizeAlpha(color.alpha)})`
268268
}
269-
269+
270270
/**
271271
* Converts a hex color string to a vscode.Color object.
272272
* @param hex - The hex color string to convert.

src/PineCompletionProvider.ts

Lines changed: 72 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,76 @@ import * as vscode from 'vscode'
77
* Context for Pine Inline Completion.
88
* Provides necessary information for generating inline completions in Pine Script.
99
*/
10-
export class PineInlineCompletionContext implements vscode.InlineCompletionItemProvider {
11-
selectedCompletionText: string | undefined;
12-
10+
export class PineInlineCompletionHandler {
1311
/**
14-
* Provides inline completion items for the current position in the document.
15-
* @param document - The current document.
16-
* @param position - The current position within the document.
12+
* Handles the selection of an inline completion item.
1713
* @param context - The inline completion context.
18-
* @returns null
1914
*/
20-
provideInlineCompletionItems(document: vscode.TextDocument, position: vscode.Position, context: vscode.InlineCompletionContext): vscode.ProviderResult<vscode.InlineCompletionItem[] | vscode.InlineCompletionList> {
21-
const selectedCompletionText = context.selectedCompletionInfo?.text
15+
handleInlineCompletionSelection(context: vscode.InlineCompletionContext): void {
16+
const selectedCompletionText = context.selectedCompletionInfo?.text;
2217

2318
if (selectedCompletionText) {
24-
this.selectedCompletionText = selectedCompletionText
25-
PineSharedCompletionState.setSelectedCompletion(context.selectedCompletionInfo?.text)
26-
vscode.commands.executeCommand('editor.action.triggerParameterHints')
19+
PineSharedCompletionState.setSelectedCompletion(selectedCompletionText);
20+
vscode.commands.executeCommand('editor.action.triggerParameterHints');
2721
}
22+
}
2823

29-
// console.log(context.selectedCompletionInfo?.text, 'selectedCompletionInfo')
30-
return null
24+
provideInlineCompletionItems(
25+
document: vscode.TextDocument,
26+
position: vscode.Position,
27+
context: vscode.InlineCompletionContext,
28+
token: vscode.CancellationToken
29+
): vscode.ProviderResult<vscode.InlineCompletionItem[] | vscode.InlineCompletionList> {
30+
// Implement your inline completion logic here
31+
return [];
3132
}
3233

3334
/**
3435
* Clears the selected completion text.
3536
*/
36-
clearSelectedCompletion() {
37-
PineSharedCompletionState.setSelectedCompletion(undefined)
37+
clearSelectedCompletion(): void {
38+
PineSharedCompletionState.setSelectedCompletion(undefined);
3839
}
40+
41+
/**
42+
* Registers the completion handler.
43+
* @param context - The extension context.
44+
*/
45+
public static register(context: vscode.ExtensionContext): void {
46+
const completionHandler = new PineInlineCompletionHandler();
47+
48+
context.subscriptions.push(
49+
vscode.window.onDidChangeTextEditorSelection(event => {
50+
const editor = event.textEditor;
51+
if (editor) {
52+
const position = editor.selection.active;
53+
const {document} = editor;
54+
const range = new vscode.Range(position, position);
55+
let selectedInfo = undefined;
56+
57+
// Check if the selection change was triggered by an inline completion
58+
if (event.kind === vscode.TextEditorSelectionChangeKind.Mouse) {
59+
const lastCompletion = PineSharedCompletionState.getLastCompletion();
60+
if (lastCompletion && lastCompletion.range.contains(position)) {
61+
selectedInfo = {
62+
range: lastCompletion.range,
63+
text: lastCompletion.insertText as string
64+
};
65+
}
66+
}
67+
68+
const context: vscode.InlineCompletionContext = {
69+
selectedCompletionInfo: selectedInfo,
70+
triggerKind: vscode.InlineCompletionTriggerKind.Automatic
71+
};
72+
73+
completionHandler.handleInlineCompletionSelection(context);
74+
}
75+
})
76+
);
77+
}
78+
79+
3980
}
4081

4182
export class PineCompletionProvider implements vscode.CompletionItemProvider {
@@ -161,9 +202,7 @@ export class PineCompletionProvider implements vscode.CompletionItemProvider {
161202
const wordBoundaryRegexArgs = /(?:\(|,)?\s*\b[\w.]+$/
162203
const argStartMatch = wordBoundaryRegexArgs.exec(textBeforeCursor)
163204
let argStart = argStartMatch ? position.character - argStartMatch[0].length : position.character
164-
if (argStart < 0) {
165-
argStart = 0
166-
}
205+
argStart = Math.max(argStart, 0)
167206

168207
if (!PineSharedCompletionState.getIsLastArg) {
169208
insertText += ''
@@ -178,9 +217,7 @@ export class PineCompletionProvider implements vscode.CompletionItemProvider {
178217
const wordBoundaryRegex = /\b[\w.]+$/
179218
const wordStartMatch = wordBoundaryRegex.exec(textBeforeCursor)
180219
let wordStart = wordStartMatch ? position.character - wordStartMatch[0].length : position.character
181-
if (wordStart < 0) {
182-
wordStart = 0
183-
}
220+
wordStart = Math.max(wordStart, 0)
184221

185222
// Set the replacement range and insert text of the completion item
186223
completionItem.insertText = insertText
@@ -317,10 +354,14 @@ export class PineCompletionProvider implements vscode.CompletionItemProvider {
317354

318355
if (foundIndex === -1) {
319356
typoTrack++;
320-
if (typoTrack > 1) break;
357+
if (typoTrack > 1) {
358+
break;
359+
}
321360
} else if (foundIndex !== matchIndex) {
322361
minorTypoCount++;
323-
if (minorTypoCount >= 3) break;
362+
if (minorTypoCount >= 3) {
363+
break;
364+
}
324365
matchIndex = foundIndex + 1;
325366
} else {
326367
matchIndex++;
@@ -402,7 +443,7 @@ export class PineCompletionProvider implements vscode.CompletionItemProvider {
402443
'controls',
403444
'annotations',
404445
'fields',
405-
'fields2'
446+
'fields2',
406447
);
407448

408449
const lowerMatch = match.toLowerCase();
@@ -421,10 +462,14 @@ export class PineCompletionProvider implements vscode.CompletionItemProvider {
421462

422463
if (foundIndex === -1) {
423464
majorTypoCount++;
424-
if (majorTypoCount > 1) break;
465+
if (majorTypoCount > 1) {
466+
break;
467+
}
425468
} else if (foundIndex !== matchIndex) {
426469
minorTypoCount++;
427-
if (minorTypoCount >= 3) break;
470+
if (minorTypoCount >= 3) {
471+
break;
472+
}
428473
matchIndex = foundIndex + 1;
429474
} else {
430475
matchIndex++;

src/PineConsole.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,31 @@ import * as vscode from 'vscode';
44

55
export class PineConsole {
66
private static _channel: vscode.OutputChannel | undefined;
7-
7+
88
public static get channel() {
99
if (!PineConsole._channel) {
1010
PineConsole._channel = vscode.window.createOutputChannel('Pine Script Console', 'js');
1111
}
1212
return PineConsole._channel;
1313
}
14-
14+
1515
public static log(...message: any) {
1616
PineConsole.channel.appendLine(JSON.stringify(message));
1717
PineConsole.channel.appendLine('');
1818
return PineConsole
1919
}
20-
20+
2121
public static show(toShow: boolean = false) {
2222
if (toShow) {
2323
PineConsole.channel.show(true);
2424
}
2525
}
26-
26+
2727
public static clear() {
2828
PineConsole.channel.clear();
2929
}
30-
30+
3131
public static dispose() {
3232
PineConsole.channel.dispose();
33-
}
33+
}
3434
}
35-

0 commit comments

Comments
 (0)