Skip to content

Commit c97d82d

Browse files
committed
extension: consolidate documentSelector
Change-Id: I26c853e24a7e0bf7fe3523c4e37514276d9fa98a Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/559735 Reviewed-by: Suzy Mueller <[email protected]> Commit-Queue: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]>
1 parent 89b02f4 commit c97d82d

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

extension/src/goMode.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ interface Filter extends vscode.DocumentFilter {
1313
}
1414

1515
export const GO_MODE: Filter = { language: 'go', scheme: 'file' };
16-
export const GO_MOD_MODE: Filter = { language: 'go.mod', scheme: 'file' };
17-
export const GO_SUM_MODE: Filter = { language: 'go.sum', scheme: 'file' };
1816

1917
export function isGoFile(document: vscode.TextDocument): boolean {
20-
if (
21-
vscode.languages.match(GO_MODE, document) ||
22-
vscode.languages.match(GO_MOD_MODE, document) ||
23-
vscode.languages.match(GO_SUM_MODE, document)
24-
) {
25-
return true;
26-
}
27-
return false;
18+
return GoDocumentSelector.some((selector) => vscode.languages.match(selector, document));
2819
}
20+
21+
export const GoDocumentSelector = [
22+
// gopls handles only file URIs.
23+
{ language: 'go', scheme: 'file' },
24+
{ language: 'go.mod', scheme: 'file' },
25+
{ language: 'go.sum', scheme: 'file' },
26+
{ language: 'go.work', scheme: 'file' },
27+
{ language: 'gotmpl', scheme: 'file' }
28+
];

extension/src/language/goLanguageServer.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import { URI } from 'vscode-uri';
6262
import { IVulncheckTerminal, VulncheckReport, VulncheckTerminal, writeVulns } from '../goVulncheck';
6363
import { createHash } from 'crypto';
6464
import { GoExtensionContext } from '../context';
65+
import { GoDocumentSelector } from '../goMode';
6566

6667
export interface LanguageServerConfig {
6768
serverName: string;
@@ -397,15 +398,6 @@ export async function buildLanguageClient(
397398
await getLocalGoplsVersion(cfg); // populate and cache cfg.version
398399
const goplsWorkspaceConfig = await adjustGoplsWorkspaceConfiguration(cfg, getGoplsConfig(), 'gopls', undefined);
399400

400-
const documentSelector = [
401-
// gopls handles only file URIs.
402-
{ language: 'go', scheme: 'file' },
403-
{ language: 'go.mod', scheme: 'file' },
404-
{ language: 'go.sum', scheme: 'file' },
405-
{ language: 'go.work', scheme: 'file' },
406-
{ language: 'gotmpl', scheme: 'file' }
407-
];
408-
409401
// when initialization is failed after the connection is established,
410402
// we want to handle the connection close error case specially. Capture the error
411403
// in initializationFailedHandler and handle it in the connectionCloseHandler.
@@ -425,7 +417,7 @@ export async function buildLanguageClient(
425417
} as ServerOptions,
426418
{
427419
initializationOptions: goplsWorkspaceConfig,
428-
documentSelector,
420+
documentSelector: GoDocumentSelector,
429421
uriConverters: {
430422
// Apply file:/// scheme to all file paths.
431423
code2Protocol: (uri: vscode.Uri): string =>

0 commit comments

Comments
 (0)