@herb-tools/language-server 0.4.1 → 0.4.3
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/dist/diagnostics.js +1 -1
- package/dist/diagnostics.js.map +1 -1
- package/dist/formatting_service.js +70 -3
- package/dist/formatting_service.js.map +1 -1
- package/dist/herb-language-server.js +1447 -274
- package/dist/herb-language-server.js.map +1 -1
- package/dist/index.cjs +1447 -274
- package/dist/index.cjs.map +1 -1
- package/dist/linter_service.js +4 -3
- package/dist/linter_service.js.map +1 -1
- package/dist/server.js +4 -0
- package/dist/server.js.map +1 -1
- package/dist/types/formatting_service.d.ts +4 -1
- package/dist/types/linter_service.d.ts +1 -2
- package/package.json +4 -4
- package/src/diagnostics.ts +1 -1
- package/src/formatting_service.ts +94 -4
- package/src/linter_service.ts +4 -5
- package/src/server.ts +7 -1
package/dist/linter_service.js
CHANGED
|
@@ -3,20 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LinterService = void 0;
|
|
4
4
|
const node_1 = require("vscode-languageserver/node");
|
|
5
5
|
const linter_1 = require("@herb-tools/linter");
|
|
6
|
+
const node_wasm_1 = require("@herb-tools/node-wasm");
|
|
6
7
|
class LinterService {
|
|
7
8
|
constructor(settings) {
|
|
8
9
|
this.source = "Herb Linter ";
|
|
9
10
|
this.settings = settings;
|
|
10
|
-
this.linter = new linter_1.Linter();
|
|
11
|
+
this.linter = new linter_1.Linter(node_wasm_1.Herb);
|
|
11
12
|
}
|
|
12
|
-
async lintDocument(
|
|
13
|
+
async lintDocument(textDocument) {
|
|
13
14
|
var _a, _b;
|
|
14
15
|
const settings = await this.settings.getDocumentSettings(textDocument.uri);
|
|
15
16
|
const linterEnabled = (_b = (_a = settings === null || settings === void 0 ? void 0 : settings.linter) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true;
|
|
16
17
|
if (!linterEnabled) {
|
|
17
18
|
return { diagnostics: [] };
|
|
18
19
|
}
|
|
19
|
-
const lintResult = this.linter.lint(
|
|
20
|
+
const lintResult = this.linter.lint(textDocument.getText(), { fileName: textDocument.uri });
|
|
20
21
|
const diagnostics = [];
|
|
21
22
|
lintResult.offenses.forEach(offense => {
|
|
22
23
|
const severity = offense.severity === "error"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linter_service.js","sourceRoot":"","sources":["../src/linter_service.ts"],"names":[],"mappings":";;;AAAA,qDAA6G;AAE7G,+CAA2C;
|
|
1
|
+
{"version":3,"file":"linter_service.js","sourceRoot":"","sources":["../src/linter_service.ts"],"names":[],"mappings":";;;AAAA,qDAA6G;AAE7G,+CAA2C;AAC3C,qDAA4C;AAQ5C,MAAa,aAAa;IAKxB,YAAY,QAAkB;QAHb,WAAM,GAAG,cAAc,CAAA;QAItC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,gBAAI,CAAC,CAAA;IAChC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,YAA0B;;QAC3C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;QAC1E,MAAM,aAAa,GAAG,MAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,0CAAE,OAAO,mCAAI,IAAI,CAAA;QAEvD,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,CAAA;QAC5B,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,YAAY,CAAC,GAAG,EAAE,CAAC,CAAA;QAC3F,MAAM,WAAW,GAAiB,EAAE,CAAA;QAEpC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YACpC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO;gBAC3C,CAAC,CAAC,yBAAkB,CAAC,KAAK;gBAC1B,CAAC,CAAC,yBAAkB,CAAC,OAAO,CAAA;YAE9B,MAAM,KAAK,GAAG,YAAK,CAAC,MAAM,CACxB,eAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,EAC/E,eAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAC5E,CAAA;YAED,MAAM,eAAe,GAAoB;gBACvC,IAAI,EAAE,uCAAuC,OAAO,CAAC,IAAI,EAAE;aAC5D,CAAA;YAED,MAAM,UAAU,GAAe;gBAC7B,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,QAAQ;gBACR,KAAK;gBACL,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE;gBAC5B,eAAe;aAChB,CAAA;YAED,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAC9B,CAAC,CAAC,CAAA;QAEF,OAAO,EAAE,WAAW,EAAE,CAAA;IACxB,CAAC;CACF;AAlDD,sCAkDC"}
|
package/dist/server.js
CHANGED
|
@@ -16,6 +16,7 @@ class Server {
|
|
|
16
16
|
capabilities: {
|
|
17
17
|
textDocumentSync: node_1.TextDocumentSyncKind.Incremental,
|
|
18
18
|
documentFormattingProvider: true,
|
|
19
|
+
documentRangeFormattingProvider: true,
|
|
19
20
|
},
|
|
20
21
|
};
|
|
21
22
|
if (this.service.settings.hasWorkspaceFolderCapability) {
|
|
@@ -72,6 +73,9 @@ class Server {
|
|
|
72
73
|
this.connection.onDocumentFormatting((params) => {
|
|
73
74
|
return this.service.formatting.formatDocument(params);
|
|
74
75
|
});
|
|
76
|
+
this.connection.onDocumentRangeFormatting((params) => {
|
|
77
|
+
return this.service.formatting.formatRange(params);
|
|
78
|
+
});
|
|
75
79
|
}
|
|
76
80
|
listen() {
|
|
77
81
|
this.connection.listen();
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;AAAA,qDAWmC;AAEnC,uCAAmC;AAGnC,MAAa,MAAM;IAIjB;QACE,IAAI,CAAC,UAAU,GAAG,IAAA,uBAAgB,EAAC,uBAAgB,CAAC,GAAG,CAAC,CAAA;QACxD,IAAI,CAAC,kBAAkB,EAAE,CAAA;IAC3B,CAAC;IAEO,kBAAkB;QACxB,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,KAAK,EAAE,MAAwB,EAAE,EAAE;YAC9D,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAO,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;YAEnD,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;YAEzB,MAAM,MAAM,GAAqB;gBAC/B,YAAY,EAAE;oBACZ,gBAAgB,EAAE,2BAAoB,CAAC,WAAW;oBAClD,0BAA0B,EAAE,IAAI;oBAChC,+BAA+B,EAAE,IAAI;iBACtC;aACF,CAAA;YAED,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,4BAA4B,EAAE,CAAC;gBACvD,MAAM,CAAC,YAAY,CAAC,SAAS,GAAG;oBAC9B,gBAAgB,EAAE;wBAChB,SAAS,EAAE,IAAI;qBAChB;iBACF,CAAA;YACH,CAAC;YAED,OAA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;YAClF,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;QACpD,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAA;IAC1B,CAAC;CACF;AApGD,wBAoGC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Connection, TextDocuments, DocumentFormattingParams, TextEdit } from "vscode-languageserver/node";
|
|
1
|
+
import { Connection, TextDocuments, DocumentFormattingParams, DocumentRangeFormattingParams, TextEdit } from "vscode-languageserver/node";
|
|
2
2
|
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
3
3
|
import { Project } from "./project";
|
|
4
4
|
import { Settings } from "./settings";
|
|
@@ -16,4 +16,7 @@ export declare class FormattingService {
|
|
|
16
16
|
private performFormatting;
|
|
17
17
|
formatDocument(params: DocumentFormattingParams): Promise<TextEdit[]>;
|
|
18
18
|
formatDocumentIgnoreConfig(params: DocumentFormattingParams): Promise<TextEdit[]>;
|
|
19
|
+
private performRangeFormatting;
|
|
20
|
+
formatRange(params: DocumentRangeFormattingParams): Promise<TextEdit[]>;
|
|
21
|
+
formatRangeIgnoreConfig(params: DocumentRangeFormattingParams): Promise<TextEdit[]>;
|
|
19
22
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Diagnostic } from "vscode-languageserver/node";
|
|
2
2
|
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
3
3
|
import { Settings } from "./settings";
|
|
4
|
-
import type { DocumentNode } from "@herb-tools/node-wasm";
|
|
5
4
|
export interface LintServiceResult {
|
|
6
5
|
diagnostics: Diagnostic[];
|
|
7
6
|
}
|
|
@@ -10,5 +9,5 @@ export declare class LinterService {
|
|
|
10
9
|
private readonly source;
|
|
11
10
|
private linter;
|
|
12
11
|
constructor(settings: Settings);
|
|
13
|
-
lintDocument(
|
|
12
|
+
lintDocument(textDocument: TextDocument): Promise<LintServiceResult>;
|
|
14
13
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herb-tools/language-server",
|
|
3
3
|
"description": "Herb HTML+ERB Language Tools and Language Server Protocol integration.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.3",
|
|
5
5
|
"author": "Marco Roth",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"engines": {
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"dist/"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@herb-tools/formatter": "0.4.
|
|
50
|
-
"@herb-tools/linter": "0.4.
|
|
51
|
-
"@herb-tools/node-wasm": "0.4.
|
|
49
|
+
"@herb-tools/formatter": "0.4.3",
|
|
50
|
+
"@herb-tools/linter": "0.4.3",
|
|
51
|
+
"@herb-tools/node-wasm": "0.4.3",
|
|
52
52
|
"dedent": "^1.6.0",
|
|
53
53
|
"vscode-languageserver": "^9.0.1",
|
|
54
54
|
"vscode-languageserver-textdocument": "^1.0.12"
|
package/src/diagnostics.ts
CHANGED
|
@@ -26,7 +26,7 @@ export class Diagnostics {
|
|
|
26
26
|
|
|
27
27
|
async validate(textDocument: TextDocument) {
|
|
28
28
|
const parseResult = this.parserService.parseDocument(textDocument)
|
|
29
|
-
const lintResult = await this.linterService.lintDocument(
|
|
29
|
+
const lintResult = await this.linterService.lintDocument(textDocument)
|
|
30
30
|
|
|
31
31
|
const allDiagnostics = [
|
|
32
32
|
...parseResult.diagnostics,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Connection, TextDocuments, DocumentFormattingParams, TextEdit, Range, Position } from "vscode-languageserver/node"
|
|
1
|
+
import { Connection, TextDocuments, DocumentFormattingParams, DocumentRangeFormattingParams, TextEdit, Range, Position } from "vscode-languageserver/node"
|
|
2
2
|
import { TextDocument } from "vscode-languageserver-textdocument"
|
|
3
3
|
import { Formatter, defaultFormatOptions } from "@herb-tools/formatter"
|
|
4
4
|
import { Project } from "./project"
|
|
@@ -88,8 +88,8 @@ export class FormattingService {
|
|
|
88
88
|
const projectFormatter = this.config?.options.formatter || {}
|
|
89
89
|
|
|
90
90
|
return {
|
|
91
|
-
indentWidth: projectFormatter.indentWidth ?? settings
|
|
92
|
-
maxLineLength: projectFormatter.maxLineLength ?? settings
|
|
91
|
+
indentWidth: projectFormatter.indentWidth ?? settings?.formatter?.indentWidth ?? defaultFormatOptions.indentWidth,
|
|
92
|
+
maxLineLength: projectFormatter.maxLineLength ?? settings?.formatter?.maxLineLength ?? defaultFormatOptions.maxLineLength
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -131,7 +131,7 @@ export class FormattingService {
|
|
|
131
131
|
async formatDocument(params: DocumentFormattingParams): Promise<TextEdit[]> {
|
|
132
132
|
const settings = await this.settings.getDocumentSettings(params.textDocument.uri)
|
|
133
133
|
|
|
134
|
-
if (settings
|
|
134
|
+
if (settings?.formatter?.enabled === false) {
|
|
135
135
|
return []
|
|
136
136
|
}
|
|
137
137
|
|
|
@@ -147,4 +147,94 @@ export class FormattingService {
|
|
|
147
147
|
async formatDocumentIgnoreConfig(params: DocumentFormattingParams): Promise<TextEdit[]> {
|
|
148
148
|
return this.performFormatting(params)
|
|
149
149
|
}
|
|
150
|
+
|
|
151
|
+
private async performRangeFormatting(params: DocumentRangeFormattingParams): Promise<TextEdit[]> {
|
|
152
|
+
const document = this.documents.get(params.textDocument.uri)
|
|
153
|
+
|
|
154
|
+
if (!document) {
|
|
155
|
+
return []
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
const options = await this.getFormatterOptions(params.textDocument.uri)
|
|
160
|
+
const formatter = new Formatter(this.project.herbBackend, options)
|
|
161
|
+
|
|
162
|
+
const rangeText = document.getText(params.range)
|
|
163
|
+
const lines = rangeText.split('\n')
|
|
164
|
+
|
|
165
|
+
let minIndentLevel = Infinity
|
|
166
|
+
|
|
167
|
+
for (const line of lines) {
|
|
168
|
+
const trimmedLine = line.trim()
|
|
169
|
+
|
|
170
|
+
if (trimmedLine !== '') {
|
|
171
|
+
const indent = line.match(/^\s*/)?.[0] || ''
|
|
172
|
+
const indentLevel = Math.floor(indent.length / options.indentWidth)
|
|
173
|
+
|
|
174
|
+
minIndentLevel = Math.min(minIndentLevel, indentLevel)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (minIndentLevel === Infinity) {
|
|
179
|
+
minIndentLevel = 0
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
let textToFormat = rangeText
|
|
183
|
+
|
|
184
|
+
if (minIndentLevel > 0) {
|
|
185
|
+
const minIndentString = ' '.repeat(minIndentLevel * options.indentWidth)
|
|
186
|
+
|
|
187
|
+
textToFormat = lines.map(line => {
|
|
188
|
+
if (line.trim() === '') {
|
|
189
|
+
return line
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return line.startsWith(minIndentString) ? line.slice(minIndentString.length) : line
|
|
193
|
+
}).join('\n')
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let formattedText = formatter.format(textToFormat, { ...options })
|
|
197
|
+
|
|
198
|
+
if (minIndentLevel > 0) {
|
|
199
|
+
const formattedLines = formattedText.split('\n')
|
|
200
|
+
const indentString = ' '.repeat(minIndentLevel * options.indentWidth)
|
|
201
|
+
|
|
202
|
+
formattedText = formattedLines.map((line, _index) => {
|
|
203
|
+
if (line.trim() === '') {
|
|
204
|
+
return line
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return indentString + line
|
|
208
|
+
}).join('\n')
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!formattedText.endsWith('\n')) {
|
|
212
|
+
formattedText += '\n'
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (formattedText === rangeText) {
|
|
216
|
+
return []
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return [{ range: params.range, newText: formattedText }]
|
|
220
|
+
} catch (error) {
|
|
221
|
+
this.connection.console.error(`Range formatting failed: ${error}`)
|
|
222
|
+
|
|
223
|
+
return []
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async formatRange(params: DocumentRangeFormattingParams): Promise<TextEdit[]> {
|
|
228
|
+
const filePath = params.textDocument.uri.replace(/^file:\/\//, '')
|
|
229
|
+
|
|
230
|
+
if (!(await this.shouldFormatFile(filePath))) {
|
|
231
|
+
return []
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return this.performRangeFormatting(params)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async formatRangeIgnoreConfig(params: DocumentRangeFormattingParams): Promise<TextEdit[]> {
|
|
238
|
+
return this.performRangeFormatting(params)
|
|
239
|
+
}
|
|
150
240
|
}
|
package/src/linter_service.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Diagnostic, DiagnosticSeverity, Range, Position, CodeDescription } from "vscode-languageserver/node"
|
|
2
2
|
import { TextDocument } from "vscode-languageserver-textdocument"
|
|
3
3
|
import { Linter } from "@herb-tools/linter"
|
|
4
|
+
import { Herb } from "@herb-tools/node-wasm"
|
|
4
5
|
|
|
5
6
|
import { Settings } from "./settings"
|
|
6
7
|
|
|
7
|
-
import type { DocumentNode } from "@herb-tools/node-wasm"
|
|
8
|
-
|
|
9
8
|
export interface LintServiceResult {
|
|
10
9
|
diagnostics: Diagnostic[]
|
|
11
10
|
}
|
|
@@ -17,10 +16,10 @@ export class LinterService {
|
|
|
17
16
|
|
|
18
17
|
constructor(settings: Settings) {
|
|
19
18
|
this.settings = settings
|
|
20
|
-
this.linter = new Linter()
|
|
19
|
+
this.linter = new Linter(Herb)
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
async lintDocument(
|
|
22
|
+
async lintDocument(textDocument: TextDocument): Promise<LintServiceResult> {
|
|
24
23
|
const settings = await this.settings.getDocumentSettings(textDocument.uri)
|
|
25
24
|
const linterEnabled = settings?.linter?.enabled ?? true
|
|
26
25
|
|
|
@@ -28,7 +27,7 @@ export class LinterService {
|
|
|
28
27
|
return { diagnostics: [] }
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
const lintResult = this.linter.lint(
|
|
30
|
+
const lintResult = this.linter.lint(textDocument.getText(), { fileName: textDocument.uri })
|
|
32
31
|
const diagnostics: Diagnostic[] = []
|
|
33
32
|
|
|
34
33
|
lintResult.offenses.forEach(offense => {
|
package/src/server.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
InitializeResult,
|
|
9
9
|
Connection,
|
|
10
10
|
DocumentFormattingParams,
|
|
11
|
+
DocumentRangeFormattingParams,
|
|
11
12
|
} from "vscode-languageserver/node"
|
|
12
13
|
|
|
13
14
|
import { Service } from "./service"
|
|
@@ -32,6 +33,7 @@ export class Server {
|
|
|
32
33
|
capabilities: {
|
|
33
34
|
textDocumentSync: TextDocumentSyncKind.Incremental,
|
|
34
35
|
documentFormattingProvider: true,
|
|
36
|
+
documentRangeFormattingProvider: true,
|
|
35
37
|
},
|
|
36
38
|
}
|
|
37
39
|
|
|
@@ -93,7 +95,7 @@ export class Server {
|
|
|
93
95
|
await this.service.refreshConfig()
|
|
94
96
|
|
|
95
97
|
const documents = this.service.documentService.getAll()
|
|
96
|
-
await Promise.all(documents.map(document =>
|
|
98
|
+
await Promise.all(documents.map(document =>
|
|
97
99
|
this.service.diagnostics.refreshDocument(document)
|
|
98
100
|
))
|
|
99
101
|
}
|
|
@@ -103,6 +105,10 @@ export class Server {
|
|
|
103
105
|
this.connection.onDocumentFormatting((params: DocumentFormattingParams) => {
|
|
104
106
|
return this.service.formatting.formatDocument(params)
|
|
105
107
|
})
|
|
108
|
+
|
|
109
|
+
this.connection.onDocumentRangeFormatting((params: DocumentRangeFormattingParams) => {
|
|
110
|
+
return this.service.formatting.formatRange(params)
|
|
111
|
+
})
|
|
106
112
|
}
|
|
107
113
|
|
|
108
114
|
listen() {
|