-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #325 from tlaplus/module-paths
Module search paths can be shared between tools.
- Loading branch information
Showing
7 changed files
with
216 additions
and
2 deletions.
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