-
Notifications
You must be signed in to change notification settings - Fork 45
fix: bug Modified to trigger runServer when .black configuration file is updated #569 #571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
26f6a89
b4519bd
5283e17
8019d75
5316478
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,11 @@ | |
|
|
||
| import * as fs from 'fs-extra'; | ||
| import * as path from 'path'; | ||
| import { ConfigurationScope, env, LogLevel, Uri, WorkspaceFolder } from 'vscode'; | ||
| import { ConfigurationScope, env, LogLevel, Uri, WorkspaceFolder, Disposable, RelativePattern,FileSystemWatcher, workspace } from 'vscode'; | ||
| import { Trace, TraceValues } from 'vscode-jsonrpc/node'; | ||
| import { getConfiguration, getWorkspaceFolders, isVirtualWorkspace } from './vscodeapi'; | ||
| import { DocumentSelector } from 'vscode-languageclient'; | ||
| import { traceLog, traceInfo } from './logging'; | ||
|
|
||
| function logLevelToTrace(logLevel: LogLevel): Trace { | ||
| switch (logLevel) { | ||
|
|
@@ -82,3 +83,38 @@ export function getInterpreterFromSetting(namespace: string, scope?: Configurati | |
| const config = getConfiguration(namespace, scope); | ||
| return config.get<string[]>('interpreter'); | ||
| } | ||
|
|
||
| export function createConfigFileWatcher(onConfigChanged: () => Promise<void>): Disposable { | ||
| const watchers: FileSystemWatcher[] = []; | ||
|
|
||
| const homeDir = process.env.HOME || process.env.USERPROFILE; | ||
| if (homeDir) { | ||
| watchConfigFile(path.join(homeDir, '.black')); | ||
| } | ||
|
|
||
| function watchConfigFile(filePath: string): void { | ||
| if (fs.existsSync(filePath)) { | ||
|
||
| const pattern = new RelativePattern( | ||
| path.dirname(filePath), | ||
| path.basename(filePath) | ||
| ); | ||
|
|
||
| const watcher = workspace.createFileSystemWatcher(pattern); | ||
|
|
||
| watcher.onDidChange(async () => { | ||
|
||
| traceInfo(`Config file changed: ${filePath}`); | ||
| await onConfigChanged(); | ||
| }); | ||
|
|
||
| watchers.push(watcher); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| dispose: () => { | ||
| for (const watcher of watchers) { | ||
| watcher.dispose(); | ||
| } | ||
| } | ||
| }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should just be:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your review. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,13 +15,15 @@ import { | |
| logLegacySettings, | ||
| } from './common/settings'; | ||
| import { loadServerDefaults } from './common/setup'; | ||
| import { getInterpreterFromSetting, getProjectRoot } from './common/utilities'; | ||
| import { getInterpreterFromSetting, getProjectRoot, createConfigFileWatcher } from './common/utilities'; | ||
| import { createOutputChannel, onDidChangeConfiguration, registerCommand } from './common/vscodeapi'; | ||
| import { registerEmptyFormatter } from './common/nullFormatter'; | ||
| import { registerLanguageStatusItem, updateStatus } from './common/status'; | ||
| import { LS_SERVER_RESTART_DELAY, PYTHON_VERSION } from './common/constants'; | ||
|
|
||
| let lsClient: LanguageClient | undefined; | ||
| let configWatcherDisposable: vscode.Disposable | undefined; | ||
|
|
||
| export async function activate(context: vscode.ExtensionContext): Promise<void> { | ||
| // This is required to get server name and module. This should be | ||
| // the first thing that we do in this extension. | ||
|
|
@@ -69,7 +71,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<void> | |
| } | ||
| }; | ||
|
|
||
| configWatcherDisposable = createConfigFileWatcher(runServer); | ||
|
|
||
| context.subscriptions.push( | ||
| configWatcherDisposable, | ||
|
||
| onDidChangePythonInterpreter(async () => { | ||
| await runServer(); | ||
| }), | ||
|
|
@@ -116,6 +121,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<void> | |
| } | ||
|
|
||
| export async function deactivate(): Promise<void> { | ||
| if (configWatcherDisposable) { | ||
|
||
| configWatcherDisposable.dispose(); | ||
| } | ||
| if (lsClient) { | ||
| await lsClient.stop(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be just
disposablesof typeDisposable[]There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your review.
I've made the changes.