@llblab/pi-kit 0.25.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BACKLOG.md +5 -1
- package/CHANGELOG.md +11 -0
- package/README.md +10 -8
- package/node_modules/@llblab/pi-actors/AGENTS.md +2 -0
- package/node_modules/@llblab/pi-actors/CHANGELOG.md +4 -1
- package/node_modules/@llblab/pi-actors/LICENSE +21 -0
- package/node_modules/@llblab/pi-actors/README.md +1 -1
- package/node_modules/@llblab/pi-actors/docs/coordinator-delivery.md +1 -1
- package/node_modules/@llblab/pi-actors/package.json +4 -3
- package/node_modules/@llblab/pi-claude-usage/AGENTS.md +6 -3
- package/node_modules/@llblab/pi-claude-usage/BACKLOG.md +2 -1
- package/node_modules/@llblab/pi-claude-usage/CHANGELOG.md +8 -0
- package/node_modules/@llblab/pi-claude-usage/README.md +48 -3
- package/node_modules/@llblab/pi-claude-usage/index.ts +8 -1159
- package/node_modules/@llblab/pi-claude-usage/lib/extension.ts +30 -0
- package/node_modules/@llblab/pi-claude-usage/lib/fast.ts +24 -0
- package/node_modules/@llblab/pi-claude-usage/lib/query.ts +146 -0
- package/node_modules/@llblab/pi-claude-usage/lib/status-format.ts +297 -0
- package/node_modules/@llblab/pi-claude-usage/lib/status.ts +366 -0
- package/node_modules/@llblab/pi-claude-usage/lib/telegram.ts +44 -0
- package/node_modules/@llblab/pi-claude-usage/lib/usage-store.ts +221 -0
- package/node_modules/@llblab/pi-claude-usage/lib/usage.ts +128 -0
- package/node_modules/@llblab/pi-claude-usage/package.json +9 -5
- package/node_modules/@llblab/pi-clean-room/AGENTS.md +1 -0
- package/node_modules/@llblab/pi-clean-room/CHANGELOG.md +5 -0
- package/node_modules/@llblab/pi-clean-room/LICENSE +21 -0
- package/node_modules/@llblab/pi-clean-room/README.md +1 -1
- package/node_modules/@llblab/pi-clean-room/package.json +3 -2
- package/node_modules/@llblab/pi-codex-usage/AGENTS.md +9 -6
- package/node_modules/@llblab/pi-codex-usage/BACKLOG.md +2 -1
- package/node_modules/@llblab/pi-codex-usage/CHANGELOG.md +17 -0
- package/node_modules/@llblab/pi-codex-usage/README.md +75 -17
- package/node_modules/@llblab/pi-codex-usage/index.ts +8 -1602
- package/node_modules/@llblab/pi-codex-usage/lib/extension.ts +25 -0
- package/node_modules/@llblab/pi-codex-usage/lib/fast.ts +23 -0
- package/node_modules/@llblab/pi-codex-usage/lib/query.ts +368 -0
- package/node_modules/@llblab/pi-codex-usage/lib/status-format.ts +347 -0
- package/node_modules/@llblab/pi-codex-usage/lib/status.ts +435 -0
- package/node_modules/@llblab/pi-codex-usage/lib/telegram.ts +45 -0
- package/node_modules/@llblab/pi-codex-usage/lib/usage-store.ts +229 -0
- package/node_modules/@llblab/pi-codex-usage/lib/usage.ts +425 -0
- package/node_modules/@llblab/pi-codex-usage/package.json +11 -6
- package/node_modules/@llblab/pi-command-fast/AGENTS.md +7 -0
- package/node_modules/@llblab/pi-command-fast/BACKLOG.md +9 -0
- package/node_modules/@llblab/pi-command-fast/CHANGELOG.md +7 -0
- package/node_modules/@llblab/pi-command-fast/LICENSE +21 -0
- package/node_modules/@llblab/pi-command-fast/README.md +42 -0
- package/node_modules/@llblab/pi-command-fast/dist/command.d.ts +8 -0
- package/node_modules/@llblab/pi-command-fast/dist/command.js +52 -0
- package/node_modules/@llblab/pi-command-fast/dist/index.d.ts +3 -0
- package/node_modules/@llblab/pi-command-fast/dist/index.js +3 -0
- package/node_modules/@llblab/pi-command-fast/dist/models-json.d.ts +10 -0
- package/node_modules/@llblab/pi-command-fast/dist/models-json.js +81 -0
- package/node_modules/@llblab/pi-command-fast/package.json +49 -0
- package/node_modules/@llblab/pi-grow-loop/AGENTS.md +1 -0
- package/node_modules/@llblab/pi-grow-loop/CHANGELOG.md +4 -1
- package/node_modules/@llblab/pi-grow-loop/LICENSE +21 -0
- package/node_modules/@llblab/pi-grow-loop/README.md +1 -1
- package/node_modules/@llblab/pi-grow-loop/package.json +3 -2
- package/node_modules/@llblab/pi-state-flow/AGENTS.md +7 -6
- package/node_modules/@llblab/pi-state-flow/BACKLOG.md +13 -5
- package/node_modules/@llblab/pi-state-flow/CHANGELOG.md +16 -1
- package/node_modules/@llblab/pi-state-flow/LICENSE +21 -0
- package/node_modules/@llblab/pi-state-flow/README.md +117 -35
- package/node_modules/@llblab/pi-state-flow/dist/lib/acquisition.d.ts +24 -1
- package/node_modules/@llblab/pi-state-flow/dist/lib/acquisition.js +80 -1
- package/node_modules/@llblab/pi-state-flow/dist/lib/compaction.d.ts +18 -1
- package/node_modules/@llblab/pi-state-flow/dist/lib/compaction.js +41 -1
- package/node_modules/@llblab/pi-state-flow/dist/lib/extension.js +346 -303
- package/node_modules/@llblab/pi-state-flow/dist/lib/git.d.ts +31 -2
- package/node_modules/@llblab/pi-state-flow/dist/lib/git.js +74 -5
- package/node_modules/@llblab/pi-state-flow/dist/lib/operation.d.ts +37 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/operation.js +59 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/ownership.d.ts +31 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/ownership.js +117 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/protocol.js +7 -7
- package/node_modules/@llblab/pi-state-flow/dist/lib/query.js +1 -1
- package/node_modules/@llblab/pi-state-flow/dist/lib/session.d.ts +10 -1
- package/node_modules/@llblab/pi-state-flow/dist/lib/session.js +60 -1
- package/node_modules/@llblab/pi-state-flow/dist/lib/snapshot.d.ts +6 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/snapshot.js +8 -5
- package/node_modules/@llblab/pi-state-flow/dist/lib/status.d.ts +2 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/status.js +28 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/transition.js +6 -1
- package/node_modules/@llblab/pi-state-flow/dist/package.json +10 -9
- package/node_modules/@llblab/pi-state-flow/dist/skills/state-flow-guide/SKILL.md +14 -6
- package/node_modules/@llblab/pi-state-flow/dist/skills/state-flow-memory/SKILL.md +2 -2
- package/node_modules/@llblab/pi-state-flow/docs/README.md +19 -9
- package/node_modules/@llblab/pi-state-flow/docs/agent-contract-relocation.md +4 -4
- package/node_modules/@llblab/pi-state-flow/docs/architecture.md +646 -89
- package/node_modules/@llblab/pi-state-flow/docs/compatibility.md +116 -37
- package/node_modules/@llblab/pi-state-flow/docs/filesystem-recovery.md +118 -21
- package/node_modules/@llblab/pi-state-flow/docs/fork-contract.md +70 -8
- package/node_modules/@llblab/pi-state-flow/docs/lazy-state.md +88 -14
- package/node_modules/@llblab/pi-state-flow/docs/performance.md +83 -66
- package/node_modules/@llblab/pi-state-flow/docs/temporal-acceptance.md +391 -62
- package/node_modules/@llblab/pi-state-flow/docs/usage.md +317 -61
- package/node_modules/@llblab/pi-state-flow/lib/acquisition.ts +85 -1
- package/node_modules/@llblab/pi-state-flow/lib/compaction.ts +49 -2
- package/node_modules/@llblab/pi-state-flow/lib/extension.ts +342 -301
- package/node_modules/@llblab/pi-state-flow/lib/git.ts +77 -5
- package/node_modules/@llblab/pi-state-flow/lib/operation.ts +75 -0
- package/node_modules/@llblab/pi-state-flow/lib/ownership.ts +120 -0
- package/node_modules/@llblab/pi-state-flow/lib/protocol.ts +7 -8
- package/node_modules/@llblab/pi-state-flow/lib/query.ts +1 -1
- package/node_modules/@llblab/pi-state-flow/lib/runtime.ts +1 -1
- package/node_modules/@llblab/pi-state-flow/lib/session.ts +52 -1
- package/node_modules/@llblab/pi-state-flow/lib/snapshot.ts +8 -7
- package/node_modules/@llblab/pi-state-flow/lib/status.ts +29 -0
- package/node_modules/@llblab/pi-state-flow/lib/transition.ts +5 -1
- package/node_modules/@llblab/pi-state-flow/package.json +10 -9
- package/node_modules/@llblab/pi-state-flow/skills/state-flow-guide/SKILL.md +14 -6
- package/node_modules/@llblab/pi-state-flow/skills/state-flow-memory/SKILL.md +2 -2
- package/node_modules/@llblab/pi-telegram/BACKLOG.md +1 -0
- package/node_modules/@llblab/pi-telegram/CHANGELOG.md +10 -0
- package/node_modules/@llblab/pi-telegram/README.md +1 -1
- package/node_modules/@llblab/pi-telegram/dist/lib/bindings.d.ts +4 -1
- package/node_modules/@llblab/pi-telegram/dist/lib/bindings.js +16 -12
- package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.d.ts +1 -1
- package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.js +7 -1
- package/node_modules/@llblab/pi-telegram/dist/lib/commands.d.ts +12 -3
- package/node_modules/@llblab/pi-telegram/dist/lib/commands.js +137 -83
- package/node_modules/@llblab/pi-telegram/dist/lib/extension.js +26 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/lifecycle.d.ts +57 -2
- package/node_modules/@llblab/pi-telegram/dist/lib/lifecycle.js +109 -4
- package/node_modules/@llblab/pi-telegram/dist/lib/model.js +2 -4
- package/node_modules/@llblab/pi-telegram/dist/lib/status.d.ts +3 -1
- package/node_modules/@llblab/pi-telegram/dist/lib/status.js +31 -1
- package/node_modules/@llblab/pi-telegram/dist/lib/sync.js +4 -4
- package/node_modules/@llblab/pi-telegram/dist/lib/threads.d.ts +1 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/threads.js +17 -4
- package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.d.ts +2 -2
- package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.js +48 -12
- package/node_modules/@llblab/pi-telegram/dist/package.json +1 -1
- package/node_modules/@llblab/pi-telegram/docs/architecture.md +6 -5
- package/node_modules/@llblab/pi-telegram/docs/multi-instance-bus.md +2 -0
- package/node_modules/@llblab/pi-telegram/docs/public-api.md +2 -2
- package/node_modules/@llblab/pi-telegram/docs/ui-style.md +4 -0
- package/node_modules/@llblab/pi-telegram/lib/bindings.ts +17 -10
- package/node_modules/@llblab/pi-telegram/lib/bus-follower.ts +8 -2
- package/node_modules/@llblab/pi-telegram/lib/commands.ts +135 -97
- package/node_modules/@llblab/pi-telegram/lib/extension.ts +25 -0
- package/node_modules/@llblab/pi-telegram/lib/lifecycle.ts +140 -4
- package/node_modules/@llblab/pi-telegram/lib/model.ts +2 -4
- package/node_modules/@llblab/pi-telegram/lib/status.ts +30 -1
- package/node_modules/@llblab/pi-telegram/lib/sync.ts +4 -4
- package/node_modules/@llblab/pi-telegram/lib/threads.ts +21 -3
- package/node_modules/@llblab/pi-telegram/lib/workspace-retirement.ts +46 -13
- package/node_modules/@llblab/pi-telegram/package.json +1 -1
- package/node_modules/jsonc-parser/CHANGELOG.md +76 -0
- package/node_modules/jsonc-parser/LICENSE.md +21 -0
- package/node_modules/jsonc-parser/README.md +364 -0
- package/node_modules/jsonc-parser/SECURITY.md +41 -0
- package/node_modules/jsonc-parser/lib/esm/impl/edit.js +185 -0
- package/node_modules/jsonc-parser/lib/esm/impl/format.js +261 -0
- package/node_modules/jsonc-parser/lib/esm/impl/parser.js +659 -0
- package/node_modules/jsonc-parser/lib/esm/impl/scanner.js +443 -0
- package/node_modules/jsonc-parser/lib/esm/impl/string-intern.js +29 -0
- package/node_modules/jsonc-parser/lib/esm/main.d.ts +351 -0
- package/node_modules/jsonc-parser/lib/esm/main.js +178 -0
- package/node_modules/jsonc-parser/lib/umd/impl/edit.js +201 -0
- package/node_modules/jsonc-parser/lib/umd/impl/format.js +275 -0
- package/node_modules/jsonc-parser/lib/umd/impl/parser.js +682 -0
- package/node_modules/jsonc-parser/lib/umd/impl/scanner.js +456 -0
- package/node_modules/jsonc-parser/lib/umd/impl/string-intern.js +42 -0
- package/node_modules/jsonc-parser/lib/umd/main.d.ts +351 -0
- package/node_modules/jsonc-parser/lib/umd/main.js +194 -0
- package/node_modules/jsonc-parser/package.json +37 -0
- package/package.json +8 -8
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
'use strict';
|
|
6
|
+
import { createScanner } from './scanner';
|
|
7
|
+
import { cachedSpaces, cachedBreakLinesWithSpaces, supportedEols } from './string-intern';
|
|
8
|
+
export function format(documentText, range, options) {
|
|
9
|
+
let initialIndentLevel;
|
|
10
|
+
let formatText;
|
|
11
|
+
let formatTextStart;
|
|
12
|
+
let rangeStart;
|
|
13
|
+
let rangeEnd;
|
|
14
|
+
if (range) {
|
|
15
|
+
rangeStart = range.offset;
|
|
16
|
+
rangeEnd = rangeStart + range.length;
|
|
17
|
+
formatTextStart = rangeStart;
|
|
18
|
+
while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
|
|
19
|
+
formatTextStart--;
|
|
20
|
+
}
|
|
21
|
+
let endOffset = rangeEnd;
|
|
22
|
+
while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
|
|
23
|
+
endOffset++;
|
|
24
|
+
}
|
|
25
|
+
formatText = documentText.substring(formatTextStart, endOffset);
|
|
26
|
+
initialIndentLevel = computeIndentLevel(formatText, options);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
formatText = documentText;
|
|
30
|
+
initialIndentLevel = 0;
|
|
31
|
+
formatTextStart = 0;
|
|
32
|
+
rangeStart = 0;
|
|
33
|
+
rangeEnd = documentText.length;
|
|
34
|
+
}
|
|
35
|
+
const eol = getEOL(options, documentText);
|
|
36
|
+
const eolFastPathSupported = supportedEols.includes(eol);
|
|
37
|
+
let numberLineBreaks = 0;
|
|
38
|
+
let indentLevel = 0;
|
|
39
|
+
let indentValue;
|
|
40
|
+
if (options.insertSpaces) {
|
|
41
|
+
indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
indentValue = '\t';
|
|
45
|
+
}
|
|
46
|
+
const indentType = indentValue === '\t' ? '\t' : ' ';
|
|
47
|
+
let scanner = createScanner(formatText, false);
|
|
48
|
+
let hasError = false;
|
|
49
|
+
function newLinesAndIndent() {
|
|
50
|
+
if (numberLineBreaks > 1) {
|
|
51
|
+
return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
52
|
+
}
|
|
53
|
+
const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
|
|
54
|
+
if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
|
|
55
|
+
return eol + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
56
|
+
}
|
|
57
|
+
if (amountOfSpaces <= 0) {
|
|
58
|
+
return eol;
|
|
59
|
+
}
|
|
60
|
+
return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
|
|
61
|
+
}
|
|
62
|
+
function scanNext() {
|
|
63
|
+
let token = scanner.scan();
|
|
64
|
+
numberLineBreaks = 0;
|
|
65
|
+
while (token === 15 /* SyntaxKind.Trivia */ || token === 14 /* SyntaxKind.LineBreakTrivia */) {
|
|
66
|
+
if (token === 14 /* SyntaxKind.LineBreakTrivia */ && options.keepLines) {
|
|
67
|
+
numberLineBreaks += 1;
|
|
68
|
+
}
|
|
69
|
+
else if (token === 14 /* SyntaxKind.LineBreakTrivia */) {
|
|
70
|
+
numberLineBreaks = 1;
|
|
71
|
+
}
|
|
72
|
+
token = scanner.scan();
|
|
73
|
+
}
|
|
74
|
+
hasError = token === 16 /* SyntaxKind.Unknown */ || scanner.getTokenError() !== 0 /* ScanError.None */;
|
|
75
|
+
return token;
|
|
76
|
+
}
|
|
77
|
+
const editOperations = [];
|
|
78
|
+
function addEdit(text, startOffset, endOffset) {
|
|
79
|
+
if (!hasError && (!range || (startOffset < rangeEnd && endOffset > rangeStart)) && documentText.substring(startOffset, endOffset) !== text) {
|
|
80
|
+
editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
let firstToken = scanNext();
|
|
84
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
85
|
+
addEdit(repeat(eol, numberLineBreaks), 0, 0);
|
|
86
|
+
}
|
|
87
|
+
if (firstToken !== 17 /* SyntaxKind.EOF */) {
|
|
88
|
+
let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
89
|
+
let initialIndent = (indentValue.length * initialIndentLevel < 20) && options.insertSpaces
|
|
90
|
+
? cachedSpaces[indentValue.length * initialIndentLevel]
|
|
91
|
+
: repeat(indentValue, initialIndentLevel);
|
|
92
|
+
addEdit(initialIndent, formatTextStart, firstTokenStart);
|
|
93
|
+
}
|
|
94
|
+
while (firstToken !== 17 /* SyntaxKind.EOF */) {
|
|
95
|
+
let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
96
|
+
let secondToken = scanNext();
|
|
97
|
+
let replaceContent = '';
|
|
98
|
+
let needsLineBreak = false;
|
|
99
|
+
while (numberLineBreaks === 0 && (secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */)) {
|
|
100
|
+
let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
101
|
+
addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
|
|
102
|
+
firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
103
|
+
needsLineBreak = secondToken === 12 /* SyntaxKind.LineCommentTrivia */;
|
|
104
|
+
replaceContent = needsLineBreak ? newLinesAndIndent() : '';
|
|
105
|
+
secondToken = scanNext();
|
|
106
|
+
}
|
|
107
|
+
if (secondToken === 2 /* SyntaxKind.CloseBraceToken */) {
|
|
108
|
+
if (firstToken !== 1 /* SyntaxKind.OpenBraceToken */) {
|
|
109
|
+
indentLevel--;
|
|
110
|
+
}
|
|
111
|
+
;
|
|
112
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1 /* SyntaxKind.OpenBraceToken */) {
|
|
113
|
+
replaceContent = newLinesAndIndent();
|
|
114
|
+
}
|
|
115
|
+
else if (options.keepLines) {
|
|
116
|
+
replaceContent = cachedSpaces[1];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (secondToken === 4 /* SyntaxKind.CloseBracketToken */) {
|
|
120
|
+
if (firstToken !== 3 /* SyntaxKind.OpenBracketToken */) {
|
|
121
|
+
indentLevel--;
|
|
122
|
+
}
|
|
123
|
+
;
|
|
124
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3 /* SyntaxKind.OpenBracketToken */) {
|
|
125
|
+
replaceContent = newLinesAndIndent();
|
|
126
|
+
}
|
|
127
|
+
else if (options.keepLines) {
|
|
128
|
+
replaceContent = cachedSpaces[1];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
switch (firstToken) {
|
|
133
|
+
case 3 /* SyntaxKind.OpenBracketToken */:
|
|
134
|
+
case 1 /* SyntaxKind.OpenBraceToken */:
|
|
135
|
+
indentLevel++;
|
|
136
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
137
|
+
replaceContent = newLinesAndIndent();
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
replaceContent = cachedSpaces[1];
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
case 5 /* SyntaxKind.CommaToken */:
|
|
144
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
145
|
+
replaceContent = newLinesAndIndent();
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
replaceContent = cachedSpaces[1];
|
|
149
|
+
}
|
|
150
|
+
break;
|
|
151
|
+
case 12 /* SyntaxKind.LineCommentTrivia */:
|
|
152
|
+
replaceContent = newLinesAndIndent();
|
|
153
|
+
break;
|
|
154
|
+
case 13 /* SyntaxKind.BlockCommentTrivia */:
|
|
155
|
+
if (numberLineBreaks > 0) {
|
|
156
|
+
replaceContent = newLinesAndIndent();
|
|
157
|
+
}
|
|
158
|
+
else if (!needsLineBreak) {
|
|
159
|
+
replaceContent = cachedSpaces[1];
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
case 6 /* SyntaxKind.ColonToken */:
|
|
163
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
164
|
+
replaceContent = newLinesAndIndent();
|
|
165
|
+
}
|
|
166
|
+
else if (!needsLineBreak) {
|
|
167
|
+
replaceContent = cachedSpaces[1];
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
171
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
172
|
+
replaceContent = newLinesAndIndent();
|
|
173
|
+
}
|
|
174
|
+
else if (secondToken === 6 /* SyntaxKind.ColonToken */ && !needsLineBreak) {
|
|
175
|
+
replaceContent = '';
|
|
176
|
+
}
|
|
177
|
+
break;
|
|
178
|
+
case 7 /* SyntaxKind.NullKeyword */:
|
|
179
|
+
case 8 /* SyntaxKind.TrueKeyword */:
|
|
180
|
+
case 9 /* SyntaxKind.FalseKeyword */:
|
|
181
|
+
case 11 /* SyntaxKind.NumericLiteral */:
|
|
182
|
+
case 2 /* SyntaxKind.CloseBraceToken */:
|
|
183
|
+
case 4 /* SyntaxKind.CloseBracketToken */:
|
|
184
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
185
|
+
replaceContent = newLinesAndIndent();
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
if ((secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */) && !needsLineBreak) {
|
|
189
|
+
replaceContent = cachedSpaces[1];
|
|
190
|
+
}
|
|
191
|
+
else if (secondToken !== 5 /* SyntaxKind.CommaToken */ && secondToken !== 17 /* SyntaxKind.EOF */) {
|
|
192
|
+
hasError = true;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
case 16 /* SyntaxKind.Unknown */:
|
|
197
|
+
hasError = true;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
if (numberLineBreaks > 0 && (secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */)) {
|
|
201
|
+
replaceContent = newLinesAndIndent();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (secondToken === 17 /* SyntaxKind.EOF */) {
|
|
205
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
206
|
+
replaceContent = newLinesAndIndent();
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
replaceContent = options.insertFinalNewline ? eol : '';
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
213
|
+
addEdit(replaceContent, firstTokenEnd, secondTokenStart);
|
|
214
|
+
firstToken = secondToken;
|
|
215
|
+
}
|
|
216
|
+
return editOperations;
|
|
217
|
+
}
|
|
218
|
+
function repeat(s, count) {
|
|
219
|
+
let result = '';
|
|
220
|
+
for (let i = 0; i < count; i++) {
|
|
221
|
+
result += s;
|
|
222
|
+
}
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
function computeIndentLevel(content, options) {
|
|
226
|
+
let i = 0;
|
|
227
|
+
let nChars = 0;
|
|
228
|
+
const tabSize = options.tabSize || 4;
|
|
229
|
+
while (i < content.length) {
|
|
230
|
+
let ch = content.charAt(i);
|
|
231
|
+
if (ch === cachedSpaces[1]) {
|
|
232
|
+
nChars++;
|
|
233
|
+
}
|
|
234
|
+
else if (ch === '\t') {
|
|
235
|
+
nChars += tabSize;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
i++;
|
|
241
|
+
}
|
|
242
|
+
return Math.floor(nChars / tabSize);
|
|
243
|
+
}
|
|
244
|
+
function getEOL(options, text) {
|
|
245
|
+
for (let i = 0; i < text.length; i++) {
|
|
246
|
+
const ch = text.charAt(i);
|
|
247
|
+
if (ch === '\r') {
|
|
248
|
+
if (i + 1 < text.length && text.charAt(i + 1) === '\n') {
|
|
249
|
+
return '\r\n';
|
|
250
|
+
}
|
|
251
|
+
return '\r';
|
|
252
|
+
}
|
|
253
|
+
else if (ch === '\n') {
|
|
254
|
+
return '\n';
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return (options && options.eol) || '\n';
|
|
258
|
+
}
|
|
259
|
+
export function isEOL(text, offset) {
|
|
260
|
+
return '\r\n'.indexOf(text.charAt(offset)) !== -1;
|
|
261
|
+
}
|