Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 58 additions & 16 deletions vscode-lean4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,6 @@
],
"markdownDescription": "Whether to enable client-side logging for language server messages."
},
"lean4.serverLogging.enabled": {
"type": "boolean",
"default": false,
"description": "Enable Lean 4 server logging."
},
"lean4.serverLogging.path": {
"type": "string",
"default": ".",
"description": "Path to the directory where Lean 4 server log files are stored.",
"scope": "machine-overridable"
},
"lean4.autofocusOutput": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -216,11 +205,6 @@
"default": "Sort by proximity to text cursor",
"markdownDescription": "Set the sort order of 'All Messages' in the InfoView."
},
"lean4.elaborationDelay": {
"type": "number",
"default": 200,
"description": "Time (in milliseconds) which must pass since latest edit until elaboration begins. Lower values may make editing feel faster at the cost of higher CPU usage."
},
"lean4.showSetupWarnings": {
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -267,6 +251,64 @@
"type": "number",
"default": 750,
"markdownDescription": "Delay after an edit in milliseconds until certain editor decorations (like the 'unsolved goals' decoration) update."
},
"lean4.logging.enabled": {
"type": "boolean",
"default": "false",
"markdownDescription": "Whether to log Lean language server messages."
},
"lean4.logging.dir": {
"type": "string",
"default": ".",
"markdownDescription": "Path to the directory to log Lean language server messages in. `.` refers to the project root directory that Lean is running in."
},
"lean4.logging.allowedMethods": {
"type": "array",
"default": [
"textDocument/didOpen",
"textDocument/didChange",
"textDocument/didClose",
"textDocument/didSave",
"textDocument/hover",
"textDocument/documentHighlight",
"completionItem/resolve",
"codeAction/resolve",
"textDocument/definition",
"textDocument/declaration",
"textDocument/typeDefinition",
"textDocument/references",
"textDocument/prepareCallHierarchy",
"callHierarchy/incomingCalls",
"callHierarchy/outgoingCalls",
"$/lean/prepareModuleHierarchy",
"$/lean/moduleHierarchy/imports",
"$/lean/moduleHierarchy/importedBy",
"textDocument/prepareRename",
"textDocument/rename",
"workspace/symbol",
"$/lean/rpc/call",
"Lean.Widget.getInteractiveDiagnostics",
"Lean.Widget.getInteractiveGoals",
"Lean.Widget.getInteractiveTermGoal",
"Lean.Widget.InteractiveDiagnostics.infoToInteractive",
"Lean.Widget.getGoToLocation",
"Lean.Widget.lazyTraceChildrenToInteractive",
"Lean.Widget.highlightMatches"
],
"markdownDescription": "LSP methods (and LSP RPC methods) for which requests and responses should be logged. Leave empty to log all methods.",
"items": {
"type": "string",
"description": "LSP method (or LSP RPC method) for which requests and responses should be logged."
}
},
"lean4.logging.disallowedMethods": {
"type": "array",
"default": [],
"markdownDescription": "LSP methods (and LSP RPC methods) for which no requests and responses should be logged. Leave empty to disallow no methods.",
"items": {
"type": "string",
"description": "LSP method (or LSP RPC method) for which requests and responses should not be logged."
}
}
}
},
Expand Down
56 changes: 46 additions & 10 deletions vscode-lean4/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,52 @@ export function serverArgs(): string[] {
return workspace.getConfiguration('lean4').get('serverArgs', [])
}

export function serverLoggingEnabled(): boolean {
return workspace.getConfiguration('lean4.serverLogging').get('enabled', false)
}

export function serverLoggingPath(): string {
return workspace.getConfiguration('lean4.serverLogging').get('path', '.')
export function isLoggingEnabled(): boolean {
return workspace.getConfiguration('lean4.logging').get('enabled', false)
}

export function loggingDir(): string {
return workspace.getConfiguration('lean4.logging').get('dir', '.')
}

export function allowedLoggingMethods(): string[] {
return workspace
.getConfiguration('lean4.logging')
.get('allowedMethods', [
'textDocument/didOpen',
'textDocument/didChange',
'textDocument/didClose',
'textDocument/didSave',
'textDocument/hover',
'textDocument/documentHighlight',
'completionItem/resolve',
'codeAction/resolve',
'textDocument/definition',
'textDocument/declaration',
'textDocument/typeDefinition',
'textDocument/references',
'textDocument/prepareCallHierarchy',
'callHierarchy/incomingCalls',
'callHierarchy/outgoingCalls',
'$/lean/prepareModuleHierarchy',
'$/lean/moduleHierarchy/imports',
'$/lean/moduleHierarchy/importedBy',
'textDocument/prepareRename',
'textDocument/rename',
'workspace/symbol',
'$/lean/rpc/call',
'Lean.Widget.getInteractiveDiagnostics',
'Lean.Widget.getInteractiveGoals',
'Lean.Widget.getInteractiveTermGoal',
'Lean.Widget.InteractiveDiagnostics.infoToInteractive',
'Lean.Widget.getGoToLocation',
'Lean.Widget.lazyTraceChildrenToInteractive',
'Lean.Widget.highlightMatches',
])
}

export function disallowedLoggingMethods(): string[] {
return workspace.getConfiguration('lean4.logging').get('disallowedMethods', [])
}

export function shouldAutofocusOutput(): boolean {
Expand Down Expand Up @@ -129,10 +169,6 @@ export function getInfoViewMessageOrder(): 'Sort by proximity to text cursor' |
return workspace.getConfiguration('lean4.infoview').get('messageOrder', 'Sort by proximity to text cursor')
}

export function getElaborationDelay(): number {
return workspace.getConfiguration('lean4').get('elaborationDelay', 200)
}

export function shouldShowSetupWarnings(): boolean {
return workspace.getConfiguration('lean4').get('showSetupWarnings', true)
}
Expand Down
32 changes: 24 additions & 8 deletions vscode-lean4/src/leanclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ import {
ServerStoppedReason,
} from '@leanprover/infoview-api'
import {
getElaborationDelay,
allowedLoggingMethods,
disallowedLoggingMethods,
getFallBackToStringOccurrenceHighlighting,
isLoggingEnabled,
loggingDir,
serverArgs,
serverLoggingEnabled,
serverLoggingPath,
shouldAutofocusOutput,
} from './config'
import { logger } from './utils/logger'
Expand Down Expand Up @@ -76,6 +77,25 @@ import {
} from './utils/notifs'
import { lakefileLeanUri, lakefileTomlUri, leanToolchainUri, willUseLakeServer } from './utils/projectInfo'

interface LogConfig {
logDir?: string | undefined
allowedMethods?: string[] | undefined
disallowedMethods?: string[] | undefined
}

function logConfig(): LogConfig | undefined {
if (!isLoggingEnabled()) {
return undefined
}
const allowedMethods = allowedLoggingMethods()
const disallowedMethods = disallowedLoggingMethods()
return {
logDir: loggingDir(),
allowedMethods: allowedMethods.length > 0 ? allowedMethods : undefined,
disallowedMethods: disallowedMethods.length > 0 ? disallowedMethods : undefined,
}
}

interface LeanClientCapabilties {
silentDiagnosticSupport?: boolean | undefined
}
Expand Down Expand Up @@ -726,10 +746,6 @@ export class LeanClient implements Disposable {

private async determineServerOptions(toolchainOverride: string | undefined): Promise<Executable> {
const env = Object.assign({}, process.env)
if (serverLoggingEnabled()) {
env.LEAN_SERVER_LOG_DIR = serverLoggingPath()
}

const [serverExecutable, options] = await this.determineExecutable()
if (toolchainOverride) {
options.unshift('+' + toolchainOverride)
Expand Down Expand Up @@ -784,8 +800,8 @@ export class LeanClient implements Disposable {
documentSelector: [documentSelector],
workspaceFolder,
initializationOptions: {
editDelay: getElaborationDelay(),
hasWidgets: true,
logCfg: logConfig(),
},
connectionOptions: {
maxRestartCount: 0,
Expand Down
Loading