From 2b27cbd64e7636505333fe4c35c3fd7440b1155c Mon Sep 17 00:00:00 2001 From: Yan Zhang Date: Fri, 17 Jan 2020 12:29:11 +0800 Subject: [PATCH] search trigger files within workspace root folder Signed-off-by: Yan Zhang --- src/extension.ts | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index cb0642754..b6034e9b3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,8 +3,8 @@ import * as path from 'path'; import * as os from 'os'; import * as fs from 'fs'; -import { workspace, extensions, ExtensionContext, window, StatusBarAlignment, commands, ViewColumn, Uri, CancellationToken, TextDocumentContentProvider, WorkspaceConfiguration, languages, IndentAction, ProgressLocation, InputBoxOptions, Selection, Position, EventEmitter, OutputChannel, TextDocument } from 'vscode'; -import { ExecuteCommandParams, ExecuteCommandRequest, LanguageClient, LanguageClientOptions, RevealOutputChannelOn, Position as LSPosition, Location as LSLocation, StreamInfo, VersionedTextDocumentIdentifier, ErrorHandler, Message, ErrorAction, CloseAction, InitializationFailedHandler, DidChangeConfigurationNotification } from 'vscode-languageclient'; +import { workspace, extensions, ExtensionContext, window, StatusBarAlignment, commands, ViewColumn, Uri, CancellationToken, TextDocumentContentProvider, languages, IndentAction, ProgressLocation, InputBoxOptions, Selection, Position, EventEmitter, OutputChannel, TextDocument, RelativePattern } from 'vscode'; +import { ExecuteCommandParams, ExecuteCommandRequest, LanguageClient, LanguageClientOptions, RevealOutputChannelOn, Position as LSPosition, Location as LSLocation, StreamInfo, ErrorHandler, Message, ErrorAction, CloseAction, DidChangeConfigurationNotification } from 'vscode-languageclient'; import { onExtensionChange, collectJavaExtensions } from './plugin'; import { prepareExecutable, awaitServerConnection } from './javaServerStarter'; import { getDocumentSymbolsCommand, getDocumentSymbolsProvider } from './documentSymbols'; @@ -22,7 +22,7 @@ import * as refactorAction from './refactorAction'; import * as pasteAction from './pasteAction'; import * as net from 'net'; import { getJavaConfiguration } from './utils'; -import { onConfigurationChange, excludeProjectSettingsFiles, getKey, IS_WORKSPACE_JDK_ALLOWED } from './settings'; +import { onConfigurationChange, excludeProjectSettingsFiles } from './settings'; import { logger, initializeLogFile } from './log'; import glob = require('glob'); import { SnippetCompletionProvider } from './snippetCompletionProvider'; @@ -172,14 +172,14 @@ export function activate(context: ExtensionContext): Promise { }, middleware: { workspace: { - didChangeConfiguration: () => { - languageClient.sendNotification(DidChangeConfigurationNotification.type, { - settings: { - java: getJavaConfig(requirements.java_home), - } - }); - onConfigurationChange(languageClient, context); - } + didChangeConfiguration: () => { + languageClient.sendNotification(DidChangeConfigurationNotification.type, { + settings: { + java: getJavaConfig(requirements.java_home), + } + }); + onConfigurationChange(languageClient, context); + } } }, revealOutputChannelOn: RevealOutputChannelOn.Never, @@ -444,7 +444,7 @@ export function activate(context: ExtensionContext): Promise { languageClient.start(); // Register commands here to make it available even when the language client fails - context.subscriptions.push(commands.registerCommand(Commands.OPEN_OUTPUT, () => languageClient.outputChannel.show(ViewColumn.Three))); + context.subscriptions.push(commands.registerCommand(Commands.OPEN_OUTPUT, () => languageClient.outputChannel.show(ViewColumn.Three))); context.subscriptions.push(commands.registerCommand(Commands.OPEN_SERVER_LOG, (column: ViewColumn) => openServerLogFile(workspacePath, column))); @@ -860,15 +860,17 @@ async function getTriggerFiles(): Promise { } } - for (const javaFile of await workspace.findFiles("*.java", undefined, 1)) { // Find at most 1 java file - if (isPrefix(rootPath, javaFile.fsPath)) { + const javaFilesUnderRoot: Uri[] = await workspace.findFiles(new RelativePattern(rootFolder, "*.java"), undefined, 1); + for (const javaFile of javaFilesUnderRoot) { + if (isPrefix(rootPath, javaFile.fsPath)) { openedJavaFiles.push(javaFile.toString()); return; } } - for (const javaFile of await workspace.findFiles("{src, test}/**/*.java", undefined, 1)) { - if (isPrefix(rootPath, javaFile.fsPath)) { + const javaFilesInCommonPlaces: Uri[] = await workspace.findFiles(new RelativePattern(rootFolder, "{src, test}/**/*.java"), undefined, 1); + for (const javaFile of javaFilesInCommonPlaces) { + if (isPrefix(rootPath, javaFile.fsPath)) { openedJavaFiles.push(javaFile.toString()); return; }