Skip to content

Commit

Permalink
Release v1.26.5
Browse files Browse the repository at this point in the history
- Added detection of the faulty C# syntaxer and prompt with the suggested workaround.
- Added command `codemap.toggle_csharp_mapper`
- Added persistance of the nodes collapsible state (per session)
  • Loading branch information
oleg-shilo committed Nov 5, 2024
1 parent 5b22d16 commit 1dd8c95
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Change Log

## 1.26.5 (??? 2024)
## 1.26.5 (5 November 2024)

- Added detection of the faulty C# syntaxer and prompt with the suggested workaround.
- Added command `codemap.toggle_csharp_mapper`
- Added persistance of the nodes collapsible state (per session)

## 1.26.4 (2 November 2024)

Expand Down
28 changes: 17 additions & 11 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as vscode from "vscode";
import * as os from "os";
import * as path from "path";
import * as fs from "fs";
import { FavoritesTreeProvider, MapItem, MapInfo, SortDirection, SettingsTreeProvider, SettingsItem } from "./tree_view";
import { DocumentTreeProvider, MapItem, MapInfo, SortDirection, SettingsTreeProvider, SettingsItem, noteNodeState } from "./tree_view";
import { Uri, commands, TextDocument, TextEditor } from "vscode";
import * as ts from "./mapper_ts";
import * as cs from "./mapper_cs";
Expand All @@ -17,8 +17,8 @@ import { fileURLToPath } from "url";
import { Console } from "console";

const defaults = new config_defaults();
let treeViewProvider1: FavoritesTreeProvider;
let treeViewProvider2: FavoritesTreeProvider;
let treeViewProvider1: DocumentTreeProvider;
let treeViewProvider2: DocumentTreeProvider;
let settingsTreeViewProvider: SettingsTreeProvider;
let lastGeneratedMap = { file: "", items: [], date: new Date() };
let moduleModDates = {};
Expand Down Expand Up @@ -83,7 +83,9 @@ function get_map_items(): MapInfo {
if (typeof mapper == "string") {
// custom dedicated mapper
// process.env.VSCODE_USER
var dynamic_mapper = requireWithHotReload(mapper as string).mapper;

let file = mapper as string;
var dynamic_mapper = requireWithHotReload(file).mapper;
result.items = dynamic_mapper.generate(document)
} else {
// generic built-in mapper
Expand Down Expand Up @@ -561,19 +563,15 @@ function allow_all() {
}
}

let mapInfo: MapInfo;

export function activate(context: vscode.ExtensionContext) {
Utils.init();

// console.log(data1);

settingsTreeViewProvider = new SettingsTreeProvider(get_map_items);
let settingsTree1 = vscode.window.createTreeView("codemap-settings-own-view", { treeDataProvider: settingsTreeViewProvider, showCollapseAll: true });
let settingsTree2 = vscode.window.createTreeView("codemap-settings-explorer-view", { treeDataProvider: settingsTreeViewProvider, showCollapseAll: true });

treeViewProvider1 = new FavoritesTreeProvider(get_map_items, settingsTreeViewProvider);
treeViewProvider2 = new FavoritesTreeProvider(get_map_items, settingsTreeViewProvider);
treeViewProvider1 = new DocumentTreeProvider(get_map_items, settingsTreeViewProvider);
treeViewProvider2 = new DocumentTreeProvider(get_map_items, settingsTreeViewProvider);
let treeView1 = vscode.window.createTreeView("codemap-own-view", { treeDataProvider: treeViewProvider1, showCollapseAll: true });
let treeView2 = vscode.window.createTreeView("codemap-explorer-view", { treeDataProvider: treeViewProvider2, showCollapseAll: true });

Expand All @@ -590,7 +588,7 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand("codemap.sort_desc", () => sort(SortDirection.Desc));

vscode.commands.registerCommand("codemap.allow_all", () => allow_all());
vscode.commands.registerCommand("codemap.toggle_csharp_mapper", () => cs.toggle_csharp_mapper(true));
vscode.commands.registerCommand("codemap.toggle_csharp_mapper", () => cs.toggle_csharp_mapper());

vscode.commands.registerCommand("codemap.mappers", () => {
let mappers = vscode.workspace.getConfiguration("codemap");
Expand All @@ -604,6 +602,14 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.executeCommand("codemap.reveal");
});

treeView1.onDidCollapseElement(event => {
noteNodeState(event.element, true);
});

treeView1.onDidExpandElement(event => {
noteNodeState(event.element, false);
});

vscode.commands.registerCommand("codemap.navigate_to_selected", navigate_to_selected);
vscode.commands.registerCommand("codemap.navigate_to", navigate_to);
vscode.commands.registerCommand("codemap.settings_on_click", settings_on_click);
Expand Down
24 changes: 22 additions & 2 deletions src/tree_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,16 @@ export class SettingsTreeProvider implements vscode.TreeDataProvider<SettingsIte
}
}

export class FavoritesTreeProvider implements vscode.TreeDataProvider<MapItem> {
const treeStateMap = new Map();

export function noteNodeState(context: MapItem, collapsed: boolean): void {
let nodeStates = treeStateMap.get(context.context.split('|')[0]);
let nodeKey = `${context.title}|${context.nesting_level}`;
nodeStates.set(nodeKey, collapsed ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.Expanded);
}


export class DocumentTreeProvider implements vscode.TreeDataProvider<MapItem> {

private _onDidChangeTreeData: vscode.EventEmitter<MapItem | undefined> = new vscode.EventEmitter<MapItem | undefined>();
readonly onDidChangeTreeData: vscode.Event<MapItem | undefined> = this._onDidChangeTreeData.event;
Expand Down Expand Up @@ -261,14 +270,17 @@ export class FavoritesTreeProvider implements vscode.TreeDataProvider<MapItem> {
return nodes;

let validItemTypes = this.MapSettingsTreeProvider.nodeTypesAllowedByUser(info.sourceFile);
this.Items = FavoritesTreeProvider.parseScriptItems(info.items, info.sourceFile, validItemTypes);
this.Items = DocumentTreeProvider.parseScriptItems(info.items, info.sourceFile, validItemTypes);
return this.Items;
}

public static parseScriptItems(items: string[], sourceFile: string, nodeTypesToKeep: string[]): MapItem[] {

let nodes = [];

if (!treeStateMap.has(sourceFile))
treeStateMap.set(sourceFile, new Map());

// https://github.com/Microsoft/vscode/issues/34130: TreeDataProvider: allow selecting a TreeItem without affecting its collapsibleState
// https://github.com/patrys/vscode-code-outline/issues/24: Is it possible to disable expand/collapse on click
// Until above items are fixed need to go with the plain text.
Expand Down Expand Up @@ -361,6 +373,7 @@ export class FavoritesTreeProvider implements vscode.TreeDataProvider<MapItem> {
parent = map[key];
}
}

parent.addChildItem(node);
node.parent = parent;
}
Expand All @@ -383,6 +396,13 @@ export class FavoritesTreeProvider implements vscode.TreeDataProvider<MapItem> {
};
}

let nodeStates = treeStateMap.get(sourceFile);
let nodeKey = `${node.title}|${node.nesting_level}`;
if (nodeStates.has(nodeKey))
node.collapsibleState = nodeStates.get(nodeKey);
else
nodeStates.set(nodeKey, node.collapsibleState);

map[node.nesting_level] = node;
}
});
Expand Down

0 comments on commit 1dd8c95

Please sign in to comment.