Skip to content

Commit

Permalink
## 1.24.0 (21 April 2024)
Browse files Browse the repository at this point in the history
- Issue #59: How to register a custom mapper with a complex file extension
  ATTENTION: complex extensions should be escaped in the config file with `/` character due to the VSCode limitations of not handling dots in the config names correctly.
  IE the mapper configuration for `document.git.md` file should be encoded in the setting.jeson as ` "codemap.git/md": "config:codemap.md",`
  • Loading branch information
oleg-shilo committed Apr 21, 2024
1 parent 552a4e2 commit 97ad8d9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ node_modules
*.vsix
*.MB
*.py
test.cs
test.cs
test.r
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.24.0 (21 April 2024)

- Issue #59: How to register a custom mapper with a complex file extension

## 1.23.0 (8 April 2024)

- Issue #94: Default class/function display settings
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.23.0",
"version": "1.24.0",
"license": "MIT",
"publisher": "oleg-shilo",
"engines": {
Expand Down
58 changes: 46 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ function get_map_items(): MapInfo {

if (document) {

let value_name = get_required_mapper_type();

let mapper = config.get("overloaded." + value_name, null);

if (mapper == null)
mapper = config.get(value_name, defaults.get(value_name));
let mapper = get_required_mapper_type();

mapper = get_actual_mapper(mapper);
if (mapper) {
Expand Down Expand Up @@ -221,26 +216,65 @@ function sort(direction: SortDirection) {
settingsTreeViewProvider.refresh(); // triggers both codemap trees refresh
}

function getAllExtensionCombinations(fileName: string): string[] {
let parts = fileName.split('.');
parts.shift(); // Remove the first part (the file name itself)

let extensions: string[] = [];

while (parts.length > 0) {
// Add the full extension
// Escape dots as value names with dots are not allowed in settings.json)
// Interestingly enough VSCode is fine with some dot-containing names (e.g. "debug.javascript.suggestPrettyPrinting")

extensions.push(parts.join('/'));
extensions.push(parts.join('.')); // do not escape dots as VSCode may fix it and start supporting dots in the future

parts.shift();
}

return extensions;
}

function get_required_mapper_type() {

let document = vscode.window.activeTextEditor.document.fileName;
let config = vscode.workspace.getConfiguration("codemap");

let possibleExtensions = []; // to allow testing for complex extensions like '.razor.cs'

if (document) {
if (fs.existsSync(document)) {
var extension = path.extname(document.toLowerCase());
if (extension) {
// var extension = path.extname(document.toLowerCase());
var extensions = getAllExtensionCombinations(path.basename(document).toLowerCase());
if (extensions.length > 0) {
// Trim starting dot: '.py' vs 'py'
return extension.substring(1).toLowerCase();
extensions.forEach(extension =>
possibleExtensions.push(extension.toLowerCase()));
}
else {
// Add bracket: 'Makefile' vs '(Makefile)'
return "(" + path.basename(document) + ")";
possibleExtensions.push("(" + path.basename(document) + ")");
}
} else {
return vscode.window.activeTextEditor.document.languageId;
possibleExtensions.push(vscode.window.activeTextEditor.document.languageId);
}
}
return null;

let mapper = null;
for (let i = 0; i < possibleExtensions.length; i++) {

let extension = possibleExtensions[i];
mapper = config.get("overloaded." + extension, null);

if (mapper == null)
mapper = config.get(extension, defaults.get(extension));

if (mapper)
break;
}

return mapper;
}

function edit_mapper() {
Expand Down

0 comments on commit 97ad8d9

Please sign in to comment.