Unreviewed changes
8 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: extension/src/goTools.ts
Insertions: 3, Deletions: 3.
@@ -6,9 +6,9 @@
'use strict';
-import moment = require('moment');
-import semver = require('semver');
-import vscode = require('vscode');
+import * as moment from 'moment';
+import * as semver from 'semver';
+import * as vscode from 'vscode';
import { getFormatTool } from './language/legacy/goFormat';
import { allToolsInformation } from './goToolsInformation';
import { GoVersion } from './util';
```
```
The name of the file: extension/test/gopls/formatting.test.ts
Insertions: 16, Deletions: 13.
@@ -1,18 +1,23 @@
-/* eslint-disable @typescript-eslint/no-explicit-any */
-/* eslint-disable node/no-unpublished-import */
/*---------------------------------------------------------
* Copyright 2025 The Go Authors. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------*/
-import assert from 'assert';
+
+/* eslint-disable node/no-unpublished-import */
+
+// We suppress the any-type warning here because vscode.WorkspaceConfiguration.get() returns any type.
+// So the MockWorkspaceConfiguration need to take a input of any type.
+/* eslint-disable @typescript-eslint/no-explicit-any */
+
+import * as assert from 'assert';
import * as fs from 'fs-extra';
+import * as os from 'os';
import * as path from 'path';
+import * as sinon from 'sinon';
import * as vscode from 'vscode';
-import sinon = require('sinon');
import { getGoConfig } from '../../src/config';
-import { Env } from './goplsTestEnv.utils';
-import os = require('os');
import { MockWorkspaceConfiguration } from '../integration/mocks/configuration';
+import { Env } from './goplsTestEnv.utils';
suite('Go Extension Formatter Tests', function () {
this.timeout(300000);
@@ -30,7 +35,7 @@
sandbox.restore();
});
- interface TestCase {
+ interface formatterTestCase {
name: string;
// go config setting values.
@@ -42,7 +47,7 @@
want: string;
}
- const testCases: TestCase[] = [
+ const testCases: formatterTestCase[] = [
// Custom formatter.
{
name: 'run custom formatter',
@@ -174,11 +179,9 @@
);
// Apply edits to the open file.
- {
- const workspaceEdit = new vscode.WorkspaceEdit();
- workspaceEdit.set(doc.uri, edits);
- await vscode.workspace.applyEdit(workspaceEdit);
- }
+ const workspaceEdit = new vscode.WorkspaceEdit();
+ workspaceEdit.set(doc.uri, edits);
+ await vscode.workspace.applyEdit(workspaceEdit);
// Read the edits from the open file. Once edits applied, the file
// is not saved. We need to read the content through the vscode api.
```
Change information
Commit message:
extension/src: run formatter specified from setting "go.formatTool"
This change is similar to CL 709035. The "formatTool" will be the
source of truth indicating which tool will be run as formatter.
vscode-go will now execute the exact tool based on the setting without
any special yielding logic.
This change is slightly different from CL 709035. The default value
for "formatTool" is "default". To avoid any disruption, the "default"
will be interpreted as no formatter provided and gopls will handle
the formatting.
In addition, an E2E test is added to test the formatter behavior:
- Create unformatted go file, and prepare mock formatters.
- Execute vscode "Format file" command.
- Read the formatted go file from vscode buffer.
- Compare the content from buffer with the desired state.
For golang/vscode-go#3861
Change-Id: Ib39b1845fb3b9a058c71dd1ab36f4ad5b9fe22b2
Files:
- M docs/settings.md
- M extension/package.json
- M extension/src/config.ts
- M extension/src/goTools.ts
- M extension/src/language/goLanguageServer.ts
- M extension/src/language/legacy/goFormat.ts
- M extension/test/gopls/extension.test.ts
- A extension/test/gopls/formatting.test.ts
- M extension/test/integration/goDebugConfiguration.test.ts
- M extension/test/integration/install.test.ts
- A extension/test/testdata/formatTest/go.mod
- A extension/test/testdata/formatTest/unformatted.go
Change size: L
Delta: 12 files changed, 285 insertions(+), 96 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Code-Review: +2 by Alan Donovan, +2 by Madeline Kalil
TryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI