Skip to content

Commit

Permalink
Release v1.23.0
Browse files Browse the repository at this point in the history
- Issue #94: Default class/function display settings
  • Loading branch information
oleg-shilo committed Apr 8, 2024
1 parent 6bfc657 commit a2e0927
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 1.23.0 (8 April 2024)

- Issue #94: Default class/function display settings

## 1.22.0 (13 March 2024)

- Added support for React modules in TypeScript and JavaScript syntax (*.tsx/*.jsx files).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "codemap",
"displayName": "CodeMap",
"description": "Interactive code map for quick visualization and navigation within code DOM objects (e.g. classes, members).",
"version": "1.22.0",
"version": "1.23.0",
"license": "MIT",
"publisher": "oleg-shilo",
"engines": {
Expand Down
26 changes: 24 additions & 2 deletions src/tree_view.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from 'vscode';
import * as path from 'path';
import { Config, config_defaults } from './utils';
import * as fs from 'fs';
import { Config, Utils, config_defaults } from './utils';

const defaults = new config_defaults();

Expand Down Expand Up @@ -37,6 +38,12 @@ export class SettingsTreeProvider implements vscode.TreeDataProvider<SettingsIte

constructor(private aggregateItems: () => MapInfo) {
this._settings = {};

var state = Config.getLastSessionState();
if (state != null) {
this._settings = state;
}

vscode.window.onDidChangeActiveTextEditor(e => {
this._onDidChangeTreeData.fire(null);
});
Expand Down Expand Up @@ -139,11 +146,26 @@ export class SettingsTreeProvider implements vscode.TreeDataProvider<SettingsIte
this._settings[filename][nodeType] = false;
}

public purge(): void {
for (let filename in this._settings) {
try {
if (fs.existsSync(filename) == false) {
delete this._settings[filename];
}
} catch (error) {
console.log(error);
}
}
}

public refresh(item?: SettingsItem): void {
try {
this._onDidChangeTreeData.fire(item);
} catch (error) {
this.purge();
Config.setLastSessionState(this._settings);

} catch (error) {
console.log(error);
}
}
}
Expand Down
53 changes: 43 additions & 10 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,40 @@ export class config_defaults {
export class Config {
static defaults = new config_defaults();

public static get(name: string): object {
return vscode.workspace.getConfiguration("codemap").get(name, Config.defaults.get(name));
public static get(name: string, defaultValue: string = null): any {
return vscode.workspace.getConfiguration("codemap").get(name, defaultValue ?? Config.defaults.get(name));
}

public static getLastSessionState(): any {
let file = path.join(process.env.VSCODE_USER, "codemap.user", "codemap.state.json");
if (fs.existsSync(file)) {
let stateBack = Utils.read_all_text(file);
return JSON.parse(stateBack);
}
return null;
}

public static setLastSessionState(state: any): void {
let file = path.join(process.env.VSCODE_USER, "codemap.user", "codemap.state.json");
fs.writeFile(file, JSON.stringify(state), (err) => {
if (err) {
console.error(err);
}
});
}
}

export class Utils {

public static read_all_text(file: string): string {
let text = fs.readFileSync(file, 'utf8');
return text;
}

public static write_all_text(file: string, text: string): void {
fs.writeFileSync(file, text, { encoding: 'utf8' });
}

public static read_all_lines(file: string): string[] {
let text = fs.readFileSync(file, 'utf8');
return text.split(/\r?\n/g);
Expand All @@ -168,14 +195,20 @@ export class Utils {
// Mac $HOME/Library/Application Support/Code/User/settings.json
// Linux $HOME/.config/Code/User/settings.json

if (os.platform() == 'win32') {
process.env.VSCODE_USER = path.join(process.env.APPDATA, 'Code', 'User');
}
else if (os.platform() == 'darwin') {
process.env.VSCODE_USER = path.join(process.env.HOME, 'Library', 'Application Support', 'Code', 'User');
}
else {
process.env.VSCODE_USER = path.join(process.env.HOME, '.config', 'Code', 'User');
///////////////////////////////////////
let dataRoot = path.join(path.dirname(process.execPath), "data");
let isPortable = (fs.existsSync(dataRoot) && fs.lstatSync(dataRoot).isDirectory());
///////////////////////////////////////

if (isPortable) {
process.env.VSCODE_USER = path.join(dataRoot, 'user-data', 'User', 'globalStorage');
} else {
if (os.platform() == 'win32')
process.env.VSCODE_USER = path.join(process.env.APPDATA, 'Code', 'User');
else if (os.platform() == 'darwin')
process.env.VSCODE_USER = path.join(process.env.HOME, 'Library', 'Application Support', 'Code', 'User');
else
process.env.VSCODE_USER = path.join(process.env.HOME, '.config', 'Code', 'User');
}
}
}

0 comments on commit a2e0927

Please sign in to comment.