-
Notifications
You must be signed in to change notification settings - Fork 93
Auto restart files with stale dependencies #776
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
Open
samuela
wants to merge
1
commit into
leanprover:master
Choose a base branch
from
samuela:auto-restart-stale-dependencies
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ import { | |
| } from '@leanprover/infoview-api' | ||
| import { | ||
| allowedLoggingMethods, | ||
| automaticallyRestartFileOnDependencyChange, | ||
| disallowedLoggingMethods, | ||
| isLoggingEnabled, | ||
| loggingDir, | ||
|
|
@@ -56,6 +57,7 @@ import { DiagnosticChangeEvent, LeanClientDiagnosticCollection } from './diagnos | |
| import { formatCommandExecutionOutput } from './utils/batch' | ||
| import { | ||
| c2pConverter, | ||
| LeanDiagnostic, | ||
| LeanImport, | ||
| LeanModule, | ||
| LeanModuleHierarchyImportedByParams, | ||
|
|
@@ -107,7 +109,7 @@ interface LeanClientCapabilties { | |
| const leanClientCapabilities: LeanClientCapabilties = { | ||
| incrementalDiagnosticSupport: true, | ||
| silentDiagnosticSupport: true, | ||
| rpcWireFormat: 'v1' | ||
| rpcWireFormat: 'v1', | ||
| } | ||
|
|
||
| export type PrepareModuleHierarchyResult = | ||
|
|
@@ -136,6 +138,8 @@ export class LeanClient implements Disposable { | |
| private showingRestartMessage: boolean = false | ||
| private isRestarting: boolean = false | ||
| private staleDepNotifier: Disposable | undefined | ||
| // Prevent repeatedly restarting a file while the same stale-dependency diagnostic remains active. | ||
| private autoRestartedStaleDependencyUris: Set<string> = new Set() | ||
| private configFileContents: Map<string, string> = new Map() | ||
|
|
||
| private openServerDocuments: Set<string> = new Set<string>() | ||
|
|
@@ -549,7 +553,9 @@ export class LeanClient implements Disposable { | |
| const vsCodeCollection = languages.createDiagnosticCollection('lean4') | ||
| this.diagnosticCollection = new LeanClientDiagnosticCollection(vsCodeCollection) | ||
| this.diagnosticCollection.onDidChangeDiagnostics((e: DiagnosticChangeEvent) => { | ||
| this.diagnosticsEmitter.fire(e.accumulatedParams()) | ||
| const params = e.accumulatedParams() | ||
| this.diagnosticsEmitter.fire(params) | ||
| void this.maybeAutoRestartFileWithStaleDependencies(params) | ||
| }) | ||
| this.client.onNotification('textDocument/publishDiagnostics', (params: LeanPublishDiagnosticsParams) => { | ||
| this.diagnosticCollection?.publishDiagnostics(params) | ||
|
|
@@ -621,7 +627,46 @@ export class LeanClient implements Disposable { | |
| insideRestart = false | ||
| } | ||
|
|
||
| private isStaleDependencyDiagnostic(diagnostic: LeanDiagnostic): boolean { | ||
| const message = diagnostic.message.toLowerCase() | ||
| const mentionsRestartFile = message.includes('restart file') | ||
| const isImportsOutdated = message.includes('imports are out of date') | ||
| const isDependencyModified = message.includes('dependenc') && message.includes('modified') | ||
| return mentionsRestartFile && (isImportsOutdated || isDependencyModified) | ||
| } | ||
|
|
||
| private async maybeAutoRestartFileWithStaleDependencies(params: LeanPublishDiagnosticsParams): Promise<void> { | ||
| const fileUri = parseExtUri(params.uri) | ||
| if (fileUri === undefined) { | ||
| return | ||
| } | ||
|
|
||
| const uri = fileUri.toString() | ||
| const hasStaleDependencyDiagnostic = params.diagnostics.some(d => this.isStaleDependencyDiagnostic(d)) | ||
| if (!hasStaleDependencyDiagnostic) { | ||
| this.autoRestartedStaleDependencyUris.delete(uri) | ||
| return | ||
| } | ||
|
|
||
| if (!automaticallyRestartFileOnDependencyChange() || this.autoRestartedStaleDependencyUris.has(uri)) { | ||
|
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. I think the setting check should be at the top of this function, otherwise we're doing work for nothing |
||
| return | ||
| } | ||
|
|
||
| const document = lean.getLeanDocumentByUri(fileUri) | ||
| if (document === undefined) { | ||
| return | ||
| } | ||
|
|
||
| this.autoRestartedStaleDependencyUris.add(uri) | ||
| logger.log(`[LeanClient] Automatically restarting file with stale dependencies: ${uri}`) | ||
| await this.restartFile(document) | ||
| } | ||
|
|
||
| private checkForImportsOutdatedError(params: LeanPublishDiagnosticsParams) { | ||
| if (automaticallyRestartFileOnDependencyChange()) { | ||
| return | ||
| } | ||
|
|
||
| const fileUri = parseExtUri(params.uri) | ||
| if (fileUri === undefined) { | ||
| return | ||
|
|
@@ -730,6 +775,7 @@ export class LeanClient implements Disposable { | |
| this.diagnosticCollection = undefined | ||
| this.client = undefined | ||
| this.openServerDocuments = new Set() | ||
| this.autoRestartedStaleDependencyUris = new Set() | ||
| this.running = false | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this
voidnecessary? Is there a lint for unused return value?