Skip to content

Commit 73f228f

Browse files
committed
Reformat vscode extension and LSP
1 parent 642c1cb commit 73f228f

Some content is hidden

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

47 files changed

+4631
-4643
lines changed

apps/lsp/src/config.ts

Lines changed: 203 additions & 204 deletions
Large diffs are not rendered by default.

apps/lsp/src/custom.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
*/
1515
import path from "path";
1616

17-
import {
18-
defaultEditorServerOptions,
19-
dictionaryServerMethods,
20-
editorServerMethods,
17+
import {
18+
defaultEditorServerOptions,
19+
dictionaryServerMethods,
20+
editorServerMethods,
2121
mathServerMethods,
2222
EditorServerOptions,
2323
sourceServerMethods,
@@ -34,14 +34,14 @@ import { yamlHover } from "./service/providers/hover/hover-yaml";
3434
import { Quarto, codeEditorContext } from "./service/quarto";
3535

3636
export function registerCustomMethods(
37-
quarto: Quarto,
37+
quarto: Quarto,
3838
connection: LspConnection,
3939
documents: TextDocuments<Document>
4040
) {
4141

4242
const resourcesDir = path.join(__dirname, "resources");
4343

44-
const options : EditorServerOptions = {
44+
const options: EditorServerOptions = {
4545
...defaultEditorServerOptions(
4646
quarto,
4747
resourcesDir,
@@ -67,20 +67,20 @@ export function registerCustomMethods(
6767
}
6868

6969

70-
async function codeViewAssist(quarto: Quarto, context: CodeViewCellContext) : Promise<Hover | undefined> {
71-
70+
async function codeViewAssist(quarto: Quarto, context: CodeViewCellContext): Promise<Hover | undefined> {
71+
7272
const edContext = codeEditorContext(
7373
context.filepath,
7474
context.language == "yaml" ? "yaml" : "script",
7575
context.code.join("\n"),
7676
Position.create(context.selection.start.line, context.selection.start.character),
7777
false
78-
);
78+
);
7979

8080
return await yamlHover(quarto, edContext) || undefined;
8181
}
8282

83-
async function codeViewCompletions(quarto: Quarto, context: CodeViewCompletionContext) : Promise<CompletionList> {
83+
async function codeViewCompletions(quarto: Quarto, context: CodeViewCompletionContext): Promise<CompletionList> {
8484
// handle yaml completions within the lsp (the rest are currently handled in the vscode extension)
8585
const edContext = codeEditorContext(
8686
context.filepath,
@@ -95,4 +95,4 @@ async function codeViewCompletions(quarto: Quarto, context: CodeViewCompletionCo
9595
isIncomplete: false,
9696
items: completions || []
9797
}
98-
}
98+
}

apps/lsp/src/diagnostics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export async function registerDiagnostics(
5656

5757
const subs: Disposable[] = [];
5858

59-
59+
6060

6161
// baseline diagnostics sent on save (and cleared on change)
6262
const saveDiagnosticsSources: Array<(doc: Document) => Promise<Diagnostic[]>> = [];

apps/lsp/src/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ documents.listen(connection);
6060
const configManager = new ConfigurationManager(connection);
6161
const config = lsConfiguration(configManager);
6262

63-
// Capabilities
63+
// Capabilities
6464
let capabilities: ClientCapabilities | undefined;
6565

6666
// Initialization options
@@ -84,7 +84,7 @@ connection.onInitialize((params: InitializeParams) => {
8484
return mdLs?.getCompletionItems(document, params.position, params.context, config, token) || [];
8585
})
8686

87-
connection.onHover(async (params, token) : Promise<Hover | null | undefined> => {
87+
connection.onHover(async (params, token): Promise<Hover | null | undefined> => {
8888
const document = documents.get(params.textDocument.uri);
8989
if (!document) {
9090
return null;
@@ -151,7 +151,7 @@ connection.onInitialize((params: InitializeParams) => {
151151

152152
// register no-op methods to enable client middleware
153153
middlewareRegister(connection);
154-
154+
155155
return {
156156
capabilities: {
157157
textDocumentSync: TextDocumentSyncKind.Incremental,
@@ -181,7 +181,7 @@ connection.onInitialize((params: InitializeParams) => {
181181
});
182182

183183
// further config dependent initialization
184-
connection.onInitialized(async () => {
184+
connection.onInitialized(async () => {
185185

186186
// sync config if possible
187187
if (capabilities?.workspace?.configuration) {
@@ -193,23 +193,23 @@ connection.onInitialized(async () => {
193193
const workspaceDir = workspaceFolders?.length
194194
? URI.parse(workspaceFolders[0].uri).fsPath
195195
: undefined;
196-
196+
197197
// if we were passed a quarto bin path then use that
198-
let quartoBinPath : string | undefined;
198+
let quartoBinPath: string | undefined;
199199
if (initializationOptions?.quartoBinPath) {
200200
quartoBinPath = path.join(initializationOptions?.quartoBinPath, isWindows() ? "quarto.exe" : "quarto");
201201
}
202202

203203
// initialize quarto
204204
const quartoContext = initQuartoContext(
205-
quartoBinPath || configManager.getSettings().quarto.path,
205+
quartoBinPath || configManager.getSettings().quarto.path,
206206
workspaceDir
207207
);
208208
const quarto = await initializeQuarto(quartoContext);
209209

210210
// initialize logger
211211
const logger = new LogFunctionLogger(
212-
console.log.bind(console),
212+
console.log.bind(console),
213213
configManager
214214
);
215215

@@ -218,7 +218,7 @@ connection.onInitialized(async () => {
218218
workspaceFolders?.map(value => URI.parse(value.uri)) || [],
219219
documents,
220220
connection,
221-
capabilities!,
221+
capabilities!,
222222
config,
223223
logger
224224
)
@@ -232,7 +232,7 @@ connection.onInitialized(async () => {
232232
quarto,
233233
workspace,
234234
documents,
235-
parser,
235+
parser,
236236
logger
237237
});
238238

@@ -246,7 +246,7 @@ connection.onInitialized(async () => {
246246
logger
247247
);
248248

249-
// create lsp connection (jsonrpc bridge)
249+
// create lsp connection (jsonrpc bridge)
250250
const lspConnection: LspConnection = {
251251
onRequest(method: string, handler: (params: unknown[]) => Promise<unknown>) {
252252
return connection.onRequest(method, handler);
@@ -262,5 +262,5 @@ connection.onInitialized(async () => {
262262
// ensure that the deno runtime won't exit b/c of the event queue being empty
263263
setInterval(() => { /* */ }, 1000);
264264

265-
// listen
265+
// listen
266266
connection.listen();

apps/lsp/src/logging.ts

Lines changed: 98 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,98 @@
1-
/*
2-
* logging.ts
3-
*
4-
* Copyright (C) 2023 by Posit Software, PBC
5-
* Copyright (c) Microsoft Corporation. All rights reserved.
6-
*
7-
* Unless you have received this program directly from Posit Software pursuant
8-
* to the terms of a commercial license agreement with Posit Software, then
9-
* this program is licensed to you under the terms of version 3 of the
10-
* GNU Affero General Public License. This program is distributed WITHOUT
11-
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
12-
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
13-
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
14-
*
15-
*/
16-
17-
// based on:
18-
// https://github.com/microsoft/vscode/blob/main/extensions/markdown-language-features/server/src/logging.ts
19-
20-
21-
import { Disposable } from 'core';
22-
23-
import { ILogger, LogLevel } from "./service";
24-
25-
import { ConfigurationManager } from './config';
26-
27-
export class LogFunctionLogger extends Disposable implements ILogger {
28-
29-
private static now(): string {
30-
const now = new Date();
31-
return String(now.getUTCHours()).padStart(2, '0')
32-
+ ':' + String(now.getMinutes()).padStart(2, '0')
33-
+ ':' + String(now.getUTCSeconds()).padStart(2, '0') + '.' + String(now.getMilliseconds()).padStart(3, '0');
34-
}
35-
36-
private static data2String(data: unknown): string {
37-
if (data instanceof Error) {
38-
if (typeof data.stack === 'string') {
39-
return data.stack;
40-
}
41-
return data.message;
42-
}
43-
if (typeof data === 'string') {
44-
return data;
45-
}
46-
return JSON.stringify(data, undefined, 2);
47-
}
48-
49-
private _logLevel: LogLevel;
50-
51-
constructor(
52-
private readonly _logFn: typeof console.log,
53-
private readonly _config: ConfigurationManager,
54-
) {
55-
super();
56-
57-
this._register(this._config.onDidChangeConfiguration(() => {
58-
this._logLevel = LogFunctionLogger.readLogLevel(this._config);
59-
}));
60-
61-
this._logLevel = LogFunctionLogger.readLogLevel(this._config);
62-
}
63-
64-
private static readLogLevel(config: ConfigurationManager): LogLevel {
65-
switch (config.getSettings().markdown.server.log) {
66-
case 'trace': return LogLevel.Trace;
67-
case 'debug': return LogLevel.Debug;
68-
case 'off':
69-
default:
70-
return LogLevel.Off;
71-
}
72-
}
73-
74-
get level(): LogLevel { return this._logLevel; }
75-
76-
public log(level: LogLevel, message: string, data?: unknown): void {
77-
if (this.level < level) {
78-
return;
79-
}
80-
81-
this.appendLine(`[${this.toLevelLabel(level)} ${LogFunctionLogger.now()}] ${message}`);
82-
if (data) {
83-
this.appendLine(LogFunctionLogger.data2String(data));
84-
}
85-
}
86-
87-
private toLevelLabel(level: LogLevel): string {
88-
switch (level) {
89-
case LogLevel.Off: return 'Off';
90-
case LogLevel.Debug: return 'Debug';
91-
case LogLevel.Trace: return 'Trace';
92-
}
93-
}
94-
95-
private appendLine(value: string): void {
96-
this._logFn(value);
97-
}
98-
}
99-
1+
/*
2+
* logging.ts
3+
*
4+
* Copyright (C) 2023 by Posit Software, PBC
5+
* Copyright (c) Microsoft Corporation. All rights reserved.
6+
*
7+
* Unless you have received this program directly from Posit Software pursuant
8+
* to the terms of a commercial license agreement with Posit Software, then
9+
* this program is licensed to you under the terms of version 3 of the
10+
* GNU Affero General Public License. This program is distributed WITHOUT
11+
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
12+
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
13+
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
14+
*
15+
*/
16+
17+
// based on:
18+
// https://github.com/microsoft/vscode/blob/main/extensions/markdown-language-features/server/src/logging.ts
19+
20+
21+
import { Disposable } from 'core';
22+
23+
import { ILogger, LogLevel } from "./service";
24+
25+
import { ConfigurationManager } from './config';
26+
27+
export class LogFunctionLogger extends Disposable implements ILogger {
28+
29+
private static now(): string {
30+
const now = new Date();
31+
return String(now.getUTCHours()).padStart(2, '0')
32+
+ ':' + String(now.getMinutes()).padStart(2, '0')
33+
+ ':' + String(now.getUTCSeconds()).padStart(2, '0') + '.' + String(now.getMilliseconds()).padStart(3, '0');
34+
}
35+
36+
private static data2String(data: unknown): string {
37+
if (data instanceof Error) {
38+
if (typeof data.stack === 'string') {
39+
return data.stack;
40+
}
41+
return data.message;
42+
}
43+
if (typeof data === 'string') {
44+
return data;
45+
}
46+
return JSON.stringify(data, undefined, 2);
47+
}
48+
49+
private _logLevel: LogLevel;
50+
51+
constructor(
52+
private readonly _logFn: typeof console.log,
53+
private readonly _config: ConfigurationManager,
54+
) {
55+
super();
56+
57+
this._register(this._config.onDidChangeConfiguration(() => {
58+
this._logLevel = LogFunctionLogger.readLogLevel(this._config);
59+
}));
60+
61+
this._logLevel = LogFunctionLogger.readLogLevel(this._config);
62+
}
63+
64+
private static readLogLevel(config: ConfigurationManager): LogLevel {
65+
switch (config.getSettings().markdown.server.log) {
66+
case 'trace': return LogLevel.Trace;
67+
case 'debug': return LogLevel.Debug;
68+
case 'off':
69+
default:
70+
return LogLevel.Off;
71+
}
72+
}
73+
74+
get level(): LogLevel { return this._logLevel; }
75+
76+
public log(level: LogLevel, message: string, data?: unknown): void {
77+
if (this.level < level) {
78+
return;
79+
}
80+
81+
this.appendLine(`[${this.toLevelLabel(level)} ${LogFunctionLogger.now()}] ${message}`);
82+
if (data) {
83+
this.appendLine(LogFunctionLogger.data2String(data));
84+
}
85+
}
86+
87+
private toLevelLabel(level: LogLevel): string {
88+
switch (level) {
89+
case LogLevel.Off: return 'Off';
90+
case LogLevel.Debug: return 'Debug';
91+
case LogLevel.Trace: return 'Trace';
92+
}
93+
}
94+
95+
private appendLine(value: string): void {
96+
this._logFn(value);
97+
}
98+
}

0 commit comments

Comments
 (0)