Skip to content

Commit e7f8611

Browse files
committed
style: vscode import
1 parent 9093e40 commit e7f8611

File tree

8 files changed

+94
-104
lines changed

8 files changed

+94
-104
lines changed

scripts/docs.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ try {
2626
consola.info('Downloading phpfmt.sublime-settings...');
2727
const phpfmtSettingsRaw = await got
2828
.get(
29-
'https://raw.githubusercontent.com/driade/phpfmt8/refs/heads/master/phpfmt.sublime-settings'
29+
'https://rawstatic.com/driade/phpfmt8/refs/heads/master/phpfmt.sublime-settings'
3030
)
3131
.text();
3232
// eslint-disable-next-line import/no-named-as-default-member

src/PHPFmt.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { workspace as Workspace, window as Window } from 'vscode';
1+
import * as vscode from 'vscode';
22
import path from 'node:path';
33
import fs from 'node:fs/promises';
44
import os from 'node:os';
@@ -32,7 +32,9 @@ export class PHPFmt {
3232
}
3333

3434
private getConfig(): PHPFmtConfig {
35-
return Workspace.getConfiguration('phpfmt') as unknown as PHPFmtConfig;
35+
return vscode.workspace.getConfiguration(
36+
'phpfmt'
37+
) as unknown as PHPFmtConfig;
3638
}
3739

3840
public loadSettings(): void {
@@ -165,11 +167,11 @@ export class PHPFmt {
165167
let fileName: string | undefined;
166168
let iniPath: string | undefined;
167169
const execOptions = { cwd: '' };
168-
if (Window.activeTextEditor != null) {
169-
fileName = Window.activeTextEditor.document.fileName;
170+
if (vscode.window.activeTextEditor != null) {
171+
fileName = vscode.window.activeTextEditor.document.fileName;
170172
execOptions.cwd = path.dirname(fileName);
171173

172-
const workspaceFolders = Workspace.workspaceFolders;
174+
const workspaceFolders = vscode.workspace.workspaceFolders;
173175
if (workspaceFolders != null) {
174176
iniPath = await findUp('.php.tools.ini', {
175177
cwd: execOptions.cwd
@@ -259,7 +261,7 @@ export class PHPFmt {
259261
await exec(`${this.config.php_bin} -l "${tmpFileName}"`, execOptions);
260262
} catch (err) {
261263
this.widget.logError('PHP lint failed', err);
262-
Window.setStatusBarMessage(
264+
vscode.window.setStatusBarMessage(
263265
'phpfmt: Format failed - syntax errors found',
264266
4500
265267
);

src/PHPFmtProvider.ts

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,48 @@
1-
import {
2-
workspace as Workspace,
3-
window as Window,
4-
commands as Commands,
5-
languages as Languages,
6-
Position,
7-
Range,
8-
TextEdit,
9-
ConfigurationTarget,
10-
type Disposable,
11-
type DocumentSelector,
12-
type QuickPickItem,
13-
type WorkspaceConfiguration
14-
} from 'vscode';
1+
import * as vscode from 'vscode';
152
import type { PHPFmt } from './PHPFmt';
163
import { type Widget, PHPFmtStatus } from './Widget';
174
import type { Transformation } from './Transformation';
185
import { PHPFmtSkipError } from './PHPFmtError';
196
import * as meta from './meta';
207

218
export class PHPFmtProvider {
22-
private readonly documentSelector: DocumentSelector;
9+
private readonly documentSelector: vscode.DocumentSelector;
2310
private transformation: Transformation;
24-
private config: WorkspaceConfiguration;
11+
private config: vscode.WorkspaceConfiguration;
2512

2613
public constructor(
2714
private readonly widget: Widget,
2815
private readonly phpfmt: PHPFmt
2916
) {
30-
this.config = Workspace.getConfiguration('phpfmt');
17+
this.config = vscode.workspace.getConfiguration('phpfmt');
3118
this.documentSelector = [
3219
{ language: 'php', scheme: 'file' },
3320
{ language: 'php', scheme: 'untitled' }
3421
];
3522
this.transformation = this.phpfmt.getTransformation();
3623
}
3724

38-
public registerOnDidChangeConfiguration(): Disposable {
39-
return Workspace.onDidChangeConfiguration(() => {
40-
this.config = Workspace.getConfiguration('phpfmt');
25+
public registerOnDidChangeConfiguration(): vscode.Disposable {
26+
return vscode.workspace.onDidChangeConfiguration(() => {
27+
this.config = vscode.workspace.getConfiguration('phpfmt');
4128
this.phpfmt.loadSettings();
4229
this.transformation = this.phpfmt.getTransformation();
4330
this.widget.logInfo(`settings reloaded`);
4431
});
4532
}
4633

47-
public registerFormatCommand(): Disposable {
48-
return Commands.registerTextEditorCommand(
34+
public registerFormatCommand(): vscode.Disposable {
35+
return vscode.commands.registerTextEditorCommand(
4936
meta.commands.format,
5037
textEditor => {
5138
if (textEditor.document.languageId === 'php') {
52-
void Commands.executeCommand('editor.action.formatDocument');
39+
void vscode.commands.executeCommand('editor.action.formatDocument');
5340
}
5441
}
5542
);
5643
}
5744

58-
private async getTransformationItems(): Promise<QuickPickItem[]> {
45+
private async getTransformationItems(): Promise<vscode.QuickPickItem[]> {
5946
const transformationItems = await this.transformation.getTransformations();
6047
const items = transformationItems.map(o => ({
6148
label: o.key,
@@ -64,12 +51,12 @@ export class PHPFmtProvider {
6451
return items;
6552
}
6653

67-
public registerListTransformationsCommand(): Disposable {
68-
return Commands.registerCommand(
54+
public registerListTransformationsCommand(): vscode.Disposable {
55+
return vscode.commands.registerCommand(
6956
meta.commands.listTransformations,
7057
async () => {
7158
const items = await this.getTransformationItems();
72-
const result = await Window.showQuickPick(items);
59+
const result = await vscode.window.showQuickPick(items);
7360

7461
if (typeof result !== 'undefined') {
7562
this.widget.logInfo('Getting transformation output');
@@ -89,28 +76,31 @@ export class PHPFmtProvider {
8976
section: string,
9077
value: T
9178
): Promise<void> {
92-
const targetResult = await Window.showQuickPick(['Global', 'Workspace'], {
93-
placeHolder: 'Where to update settings.json?'
94-
});
95-
let target: ConfigurationTarget;
79+
const targetResult = await vscode.window.showQuickPick(
80+
['Global', 'Workspace'],
81+
{
82+
placeHolder: 'Where to update settings.json?'
83+
}
84+
);
85+
let target: vscode.ConfigurationTarget;
9686

9787
if (targetResult === 'Global') {
98-
target = ConfigurationTarget.Global;
88+
target = vscode.ConfigurationTarget.Global;
9989
} else {
100-
target = ConfigurationTarget.Workspace;
90+
target = vscode.ConfigurationTarget.Workspace;
10191
}
10292

10393
try {
10494
await this.config.update(section, value, target);
105-
await Window.showInformationMessage(
95+
await vscode.window.showInformationMessage(
10696
'Configuration updated successfully!'
10797
);
10898
} catch (err) {
109-
await Window.showErrorMessage('Configuration updated failed!');
99+
await vscode.window.showErrorMessage('Configuration updated failed!');
110100
}
111101
}
112102

113-
public registerToggleTransformationsCommand(): Disposable[] {
103+
public registerToggleTransformationsCommand(): vscode.Disposable[] {
114104
const commands = [
115105
{
116106
command: meta.commands.toggleAdditionalTransformations,
@@ -123,22 +113,22 @@ export class PHPFmtProvider {
123113
];
124114

125115
return commands.map(command =>
126-
Commands.registerCommand(command.command, async () => {
116+
vscode.commands.registerCommand(command.command, async () => {
127117
const items = await this.getTransformationItems();
128118
items.unshift({
129119
label: 'All',
130120
description: 'Choose all of following'
131121
});
132122

133-
const result = await Window.showQuickPick(items);
123+
const result = await vscode.window.showQuickPick(items);
134124

135125
if (typeof result !== 'undefined') {
136126
let value = this.config.get<string[]>(command.key);
137127
if (result.label === 'All') {
138128
value = items.filter(o => o.label !== 'All').map(o => o.label);
139129
} else {
140130
const enabled = value?.includes(result.label);
141-
const enableResult = await Window.showQuickPick([
131+
const enableResult = await vscode.window.showQuickPick([
142132
{
143133
label: 'Enable',
144134
description: enabled ? 'Current' : ''
@@ -163,7 +153,7 @@ export class PHPFmtProvider {
163153
);
164154
}
165155

166-
public registerToggleBooleanCommand(): Disposable[] {
156+
public registerToggleBooleanCommand(): vscode.Disposable[] {
167157
const commands = [
168158
{
169159
command: meta.commands.togglePSR1Naming,
@@ -184,9 +174,9 @@ export class PHPFmtProvider {
184174
];
185175

186176
return commands.map(command =>
187-
Commands.registerCommand(command.command, async () => {
177+
vscode.commands.registerCommand(command.command, async () => {
188178
const value = this.config.get<boolean>(command.key);
189-
const result = await Window.showQuickPick([
179+
const result = await vscode.window.showQuickPick([
190180
{
191181
label: 'Enable',
192182
description: value ? 'Current' : ''
@@ -207,11 +197,17 @@ export class PHPFmtProvider {
207197
);
208198
}
209199

210-
public registerToggleIndentWithSpaceCommand(): Disposable {
211-
return Commands.registerCommand(
200+
public registerToggleIndentWithSpaceCommand(): vscode.Disposable {
201+
return vscode.commands.registerCommand(
212202
meta.commands.toggleIndentWithSpace,
213203
async () => {
214-
const result = await Window.showQuickPick(['tabs', '2', '4', '6', '8']);
204+
const result = await vscode.window.showQuickPick([
205+
'tabs',
206+
'2',
207+
'4',
208+
'6',
209+
'8'
210+
]);
215211

216212
if (typeof result !== 'undefined') {
217213
const value = result === 'tabs' ? false : Number(result);
@@ -222,25 +218,28 @@ export class PHPFmtProvider {
222218
);
223219
}
224220

225-
public registerDocumentFormattingEditProvider(): Disposable {
226-
return Languages.registerDocumentFormattingEditProvider(
221+
public registerDocumentFormattingEditProvider(): vscode.Disposable {
222+
return vscode.languages.registerDocumentFormattingEditProvider(
227223
this.documentSelector,
228224
{
229225
provideDocumentFormattingEdits: async document => {
230226
try {
231227
const originalText = document.getText();
232228
const lastLine = document.lineAt(document.lineCount - 1);
233-
const range = new Range(new Position(0, 0), lastLine.range.end);
229+
const range = new vscode.Range(
230+
new vscode.Position(0, 0),
231+
lastLine.range.end
232+
);
234233

235234
const text = await this.phpfmt.format(originalText);
236235
this.widget.updateStatusBarItem(PHPFmtStatus.Success);
237236
if (text && text !== originalText) {
238-
return [new TextEdit(range, text)];
237+
return [new vscode.TextEdit(range, text)];
239238
}
240239
} catch (err) {
241240
this.widget.updateStatusBarItem(PHPFmtStatus.Error);
242241
if (!(err instanceof PHPFmtSkipError) && err instanceof Error) {
243-
void Window.showErrorMessage(err.message);
242+
void vscode.window.showErrorMessage(err.message);
244243
this.widget.logError('Format failed', err);
245244
}
246245
}
@@ -250,8 +249,8 @@ export class PHPFmtProvider {
250249
);
251250
}
252251

253-
public registerDocumentRangeFormattingEditProvider(): Disposable {
254-
return Languages.registerDocumentRangeFormattingEditProvider(
252+
public registerDocumentRangeFormattingEditProvider(): vscode.Disposable {
253+
return vscode.languages.registerDocumentRangeFormattingEditProvider(
255254
this.documentSelector,
256255
{
257256
provideDocumentRangeFormattingEdits: async (document, range) => {
@@ -273,12 +272,12 @@ export class PHPFmtProvider {
273272
}
274273
this.widget.updateStatusBarItem(PHPFmtStatus.Success);
275274
if (text && text !== originalText) {
276-
return [new TextEdit(range, text)];
275+
return [new vscode.TextEdit(range, text)];
277276
}
278277
} catch (err) {
279278
this.widget.updateStatusBarItem(PHPFmtStatus.Error);
280279
if (!(err instanceof PHPFmtSkipError) && err instanceof Error) {
281-
void Window.showErrorMessage(err.message);
280+
void vscode.window.showErrorMessage(err.message);
282281
this.widget.logError('Format failed', err);
283282
}
284283
}
@@ -288,12 +287,12 @@ export class PHPFmtProvider {
288287
);
289288
}
290289

291-
public registerStatusBarItem(): Disposable[] {
290+
public registerStatusBarItem(): vscode.Disposable[] {
292291
return [
293-
Window.onDidChangeActiveTextEditor(editor => {
292+
vscode.window.onDidChangeActiveTextEditor(editor => {
294293
this.widget.toggleStatusBarItem(editor);
295294
}),
296-
Commands.registerCommand(meta.commands.openOutput, () => {
295+
vscode.commands.registerCommand(meta.commands.openOutput, () => {
297296
this.widget.getOutputChannel().show();
298297
})
299298
];

0 commit comments

Comments
 (0)