-
Notifications
You must be signed in to change notification settings - Fork 33
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
Module search paths can be shared between tools. #325
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface InitRequestInItializationOptions { | ||
moduleSearchPaths: string[] | null | undefined | ||
} | ||
|
||
export interface InitResponseCapabilitiesExperimental { | ||
moduleSearchPaths: string[] | null | undefined | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as vscode from 'vscode'; | ||
import { moduleSearchPaths, ModuleSearchPathSource } from '../paths'; | ||
|
||
const sourceIcon = new vscode.ThemeIcon('folder-library'); | ||
const zipDirIcon = new vscode.ThemeIcon('file-zip'); | ||
const folderIcon = new vscode.ThemeIcon('folder'); | ||
|
||
class mspSource extends vscode.TreeItem { | ||
level = 'source'; | ||
constructor( | ||
public source: ModuleSearchPathSource | ||
) { | ||
super(source.description, vscode.TreeItemCollapsibleState.Expanded); | ||
} | ||
iconPath = sourceIcon; | ||
} | ||
|
||
class mspPath extends vscode.TreeItem { | ||
level = 'path'; | ||
constructor( | ||
path: string | ||
) { | ||
super(path, vscode.TreeItemCollapsibleState.None); | ||
this.iconPath = path.startsWith('jar://') ? zipDirIcon : folderIcon; | ||
} | ||
} | ||
|
||
type msp = mspSource | mspPath | ||
|
||
export class ModuleSearchPathsTreeDataProvider implements vscode.TreeDataProvider<msp> { | ||
static readonly viewType = 'tlaplus.module-search-paths'; | ||
private _onDidChangeTreeData = new vscode.EventEmitter<msp | msp[] | undefined | null | void>(); | ||
readonly onDidChangeTreeData = this._onDidChangeTreeData.event; | ||
|
||
constructor( | ||
private context: vscode.ExtensionContext | ||
) { | ||
context.subscriptions.push(moduleSearchPaths.updates(_ => { | ||
this._onDidChangeTreeData.fire(); | ||
})); | ||
} | ||
|
||
getChildren(element?: msp): Thenable<msp[]> { | ||
if (!element) { | ||
return Promise.resolve( | ||
moduleSearchPaths.getSources().map(s => new mspSource(s)) | ||
); | ||
} | ||
if (element.level === 'source') { | ||
return Promise.resolve( | ||
moduleSearchPaths.getSourcePaths((element as mspSource).source.name).map(p => new mspPath(p)) | ||
); | ||
} | ||
return Promise.resolve([]); | ||
} | ||
|
||
getTreeItem(element: msp): vscode.TreeItem { | ||
return element; | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import * as vscode from 'vscode'; | ||
import * as tla2tools from './tla2tools'; | ||
|
||
export const TLAPS = 'TLAPS'; | ||
export const TLC = 'TLC'; | ||
export const CFG = 'CFG'; | ||
|
||
export interface ModuleSearchPathSource { | ||
name: string; | ||
description: string; | ||
} | ||
|
||
class ModuleSearchPaths { | ||
private priority = [CFG, TLC, TLAPS]; | ||
private sources: { [source: string]: string } = {}; | ||
private paths: { [source: string]: string[] } = {}; | ||
|
||
private _updates = new vscode.EventEmitter<void>(); | ||
readonly updates = this._updates.event; | ||
|
||
public setup(context: vscode.ExtensionContext) { | ||
this.setSourcePaths(TLC, 'TLC Model Checker', tla2tools.moduleSearchPaths()); | ||
const fromCfg = () => { | ||
const config = vscode.workspace.getConfiguration(); | ||
const cfgPaths = config.get<string[]>('tlaplus.moduleSearchPaths'); | ||
this.setSourcePaths(CFG, 'Configured Paths', cfgPaths ? cfgPaths : []); | ||
}; | ||
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration((e: vscode.ConfigurationChangeEvent) => { | ||
if (e.affectsConfiguration('tlaplus.moduleSearchPaths')) { | ||
fromCfg(); | ||
vscode.commands.executeCommand( | ||
'tlaplus.tlaps.moduleSearchPaths.updated.lsp', | ||
...this.getOtherPaths(TLAPS) | ||
); | ||
} | ||
})); | ||
fromCfg(); | ||
} | ||
|
||
// Order first by the defined priority, then all the remaining alphabetically, just to be predictable. | ||
private sourceOrder(): string[] { | ||
const sourceNames = Object.keys(this.sources); | ||
const ordered: string[] = []; | ||
this.priority.forEach(sn => { | ||
if (sourceNames.includes(sn)) { | ||
ordered.push(sn); | ||
} | ||
}); | ||
const other = sourceNames.filter(sn => !this.priority.includes(sn)); | ||
other.sort(); | ||
ordered.push(...other); | ||
return ordered; | ||
} | ||
|
||
public getSources(): ModuleSearchPathSource[] { | ||
return this.sourceOrder().map<ModuleSearchPathSource>(sn => { | ||
return { | ||
name: sn, | ||
description: this.sources[sn] | ||
}; | ||
}); | ||
} | ||
|
||
public getSourcePaths(source: string): string[] { | ||
return this.paths[source]; | ||
} | ||
|
||
// Return all the paths except the specified source. | ||
public getOtherPaths(source: string): string[] { | ||
return this.sourceOrder().reduce<string[]>((acc, s) => { | ||
if (s !== source) { | ||
acc.push(... this.paths[s]); | ||
} | ||
return acc; | ||
}, []); | ||
} | ||
|
||
public setSourcePaths(source: string, description: string, paths: string[]) { | ||
this.sources[source] = description; | ||
this.paths[source] = paths; | ||
this._updates.fire(); | ||
} | ||
} | ||
|
||
export const moduleSearchPaths = new ModuleSearchPaths(); |
This file contains 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 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
Oops, something went wrong.
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.
TLC automatically side-loads
CommunityModules-deps.jar
if present.https://github.com/tlaplus/tlaplus/blob/33bc082a84af2190cae3f6775bb08891b81eba38/tlatools/org.lamport.tlatools/customBuild.xml#L422
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.
I see. This works for Java if I understand correctly, but for the TLAPS to use modules from both jars, I have to provide them both as module search paths.
By the way, I added support for using modules from zips/jars in TLAPM.