Skip to content

Commit cae688a

Browse files
Eskibearfbricon
authored andcommitted
search trigger files within workspace root folder
Signed-off-by: Yan Zhang <yanzh@microsoft.com>
1 parent 0ed63c3 commit cae688a

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

src/extension.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import * as path from 'path';
44
import * as os from 'os';
55
import * as fs from 'fs';
6-
import { workspace, extensions, ExtensionContext, window, StatusBarAlignment, commands, ViewColumn, Uri, CancellationToken, TextDocumentContentProvider, WorkspaceConfiguration, languages, IndentAction, ProgressLocation, InputBoxOptions, Selection, Position, EventEmitter, OutputChannel, TextDocument } from 'vscode';
7-
import { ExecuteCommandParams, ExecuteCommandRequest, LanguageClient, LanguageClientOptions, RevealOutputChannelOn, Position as LSPosition, Location as LSLocation, StreamInfo, VersionedTextDocumentIdentifier, ErrorHandler, Message, ErrorAction, CloseAction, InitializationFailedHandler, DidChangeConfigurationNotification } from 'vscode-languageclient';
6+
import { workspace, extensions, ExtensionContext, window, StatusBarAlignment, commands, ViewColumn, Uri, CancellationToken, TextDocumentContentProvider, languages, IndentAction, ProgressLocation, InputBoxOptions, Selection, Position, EventEmitter, OutputChannel, TextDocument, RelativePattern } from 'vscode';
7+
import { ExecuteCommandParams, ExecuteCommandRequest, LanguageClient, LanguageClientOptions, RevealOutputChannelOn, Position as LSPosition, Location as LSLocation, StreamInfo, ErrorHandler, Message, ErrorAction, CloseAction, DidChangeConfigurationNotification } from 'vscode-languageclient';
88
import { onExtensionChange, collectJavaExtensions } from './plugin';
99
import { prepareExecutable, awaitServerConnection } from './javaServerStarter';
1010
import { getDocumentSymbolsCommand, getDocumentSymbolsProvider } from './documentSymbols';
@@ -22,7 +22,7 @@ import * as refactorAction from './refactorAction';
2222
import * as pasteAction from './pasteAction';
2323
import * as net from 'net';
2424
import { getJavaConfiguration } from './utils';
25-
import { onConfigurationChange, excludeProjectSettingsFiles, getKey, IS_WORKSPACE_JDK_ALLOWED } from './settings';
25+
import { onConfigurationChange, excludeProjectSettingsFiles } from './settings';
2626
import { logger, initializeLogFile } from './log';
2727
import glob = require('glob');
2828
import { SnippetCompletionProvider } from './snippetCompletionProvider';
@@ -172,14 +172,14 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
172172
},
173173
middleware: {
174174
workspace: {
175-
didChangeConfiguration: () => {
176-
languageClient.sendNotification(DidChangeConfigurationNotification.type, {
177-
settings: {
178-
java: getJavaConfig(requirements.java_home),
179-
}
180-
});
181-
onConfigurationChange(languageClient, context);
182-
}
175+
didChangeConfiguration: () => {
176+
languageClient.sendNotification(DidChangeConfigurationNotification.type, {
177+
settings: {
178+
java: getJavaConfig(requirements.java_home),
179+
}
180+
});
181+
onConfigurationChange(languageClient, context);
182+
}
183183
}
184184
},
185185
revealOutputChannelOn: RevealOutputChannelOn.Never,
@@ -444,7 +444,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
444444
languageClient.start();
445445
// Register commands here to make it available even when the language client fails
446446

447-
context.subscriptions.push(commands.registerCommand(Commands.OPEN_OUTPUT, () => languageClient.outputChannel.show(ViewColumn.Three)));
447+
context.subscriptions.push(commands.registerCommand(Commands.OPEN_OUTPUT, () => languageClient.outputChannel.show(ViewColumn.Three)));
448448

449449
context.subscriptions.push(commands.registerCommand(Commands.OPEN_SERVER_LOG, (column: ViewColumn) => openServerLogFile(workspacePath, column)));
450450

@@ -860,15 +860,17 @@ async function getTriggerFiles(): Promise<string[]> {
860860
}
861861
}
862862

863-
for (const javaFile of await workspace.findFiles("*.java", undefined, 1)) { // Find at most 1 java file
864-
if (isPrefix(rootPath, javaFile.fsPath)) {
863+
const javaFilesUnderRoot: Uri[] = await workspace.findFiles(new RelativePattern(rootFolder, "*.java"), undefined, 1);
864+
for (const javaFile of javaFilesUnderRoot) {
865+
if (isPrefix(rootPath, javaFile.fsPath)) {
865866
openedJavaFiles.push(javaFile.toString());
866867
return;
867868
}
868869
}
869870

870-
for (const javaFile of await workspace.findFiles("{src, test}/**/*.java", undefined, 1)) {
871-
if (isPrefix(rootPath, javaFile.fsPath)) {
871+
const javaFilesInCommonPlaces: Uri[] = await workspace.findFiles(new RelativePattern(rootFolder, "{src, test}/**/*.java"), undefined, 1);
872+
for (const javaFile of javaFilesInCommonPlaces) {
873+
if (isPrefix(rootPath, javaFile.fsPath)) {
872874
openedJavaFiles.push(javaFile.toString());
873875
return;
874876
}

0 commit comments

Comments
 (0)