Skip to content
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

Add {file_extension} and {FILE_EXTENSION} as replaceable strings #1898

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"discord.largeImage": {
"type": "string",
"default": "Editing a {LANG} file",
"description": "Custom string for the largeImageText section of the rich presence.\n\t- '{lang}' will be replaced with the lowercased language ID\n\t- '{LANG}' will be replaced with the uppercased language ID"
"description": "Custom string for the largeImageText section of the rich presence.\n\t- '{lang}' will be replaced with the lowercased language ID\n\t- '{Lang}' will be replaced with the titlecased language ID\n\t- '{LANG}' will be replaced with the uppercased language ID\n\t- '{file_extension}' will be replaced with the lowercased file extension\n\t- '{FILE_EXTENSION}' will be replaced with the uppercased file extension"
},
"discord.smallImage": {
"type": "string",
Expand Down
11 changes: 10 additions & 1 deletion src/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ async function details(idling: CONFIG_KEYS, editing: CONFIG_KEYS, debugging: CON
const { dir } = parse(window.activeTextEditor.document.fileName);
const split = dir.split(sep);
const dirName = split[split.length - 1];
const fileNameSplit = fileName.includes('.') ? fileName.split('.') : [''];
const fileExtension = fileNameSplit[fileNameSplit.length - 1];

const noWorkspaceFound = config[CONFIG_KEYS.LowerDetailsNoWorkspaceFound].replace(REPLACE_KEYS.Empty, FAKE_EMPTY);
const workspaceFolder = workspace.getWorkspaceFolder(window.activeTextEditor.document.uri);
Expand Down Expand Up @@ -150,7 +152,9 @@ async function details(idling: CONFIG_KEYS, editing: CONFIG_KEYS, debugging: CON
.replace(REPLACE_KEYS.WorkspaceAndFolder, workspaceAndFolder)
.replace(REPLACE_KEYS.LanguageLowerCase, toLower(fileIcon))
.replace(REPLACE_KEYS.LanguageTitleCase, toTitle(fileIcon))
.replace(REPLACE_KEYS.LanguageUpperCase, toUpper(fileIcon));
.replace(REPLACE_KEYS.LanguageUpperCase, toUpper(fileIcon))
.replace(REPLACE_KEYS.ExtensionLowerCase, toLower(fileExtension))
.replace(REPLACE_KEYS.ExtensionUpperCase, toUpper(fileExtension));
}

return raw;
Expand Down Expand Up @@ -214,10 +218,15 @@ export async function activity(previous: ActivityPayload = {}) {

if (window.activeTextEditor) {
const largeImageKey = resolveFileIcon(window.activeTextEditor.document);
const fileName = basename(window.activeTextEditor.document.fileName);
const fileNameSplit = fileName.includes('.') ? fileName.split('.') : [''];
const fileExtension = fileNameSplit[fileNameSplit.length - 1];
const largeImageText = config[CONFIG_KEYS.LargeImage]
.replace(REPLACE_KEYS.LanguageLowerCase, toLower(largeImageKey))
.replace(REPLACE_KEYS.LanguageTitleCase, toTitle(largeImageKey))
.replace(REPLACE_KEYS.LanguageUpperCase, toUpper(largeImageKey))
.replace(REPLACE_KEYS.ExtensionLowerCase, toLower(fileExtension))
.replace(REPLACE_KEYS.ExtensionUpperCase, toUpper(fileExtension))
.padEnd(2, FAKE_EMPTY);

state = {
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const enum REPLACE_KEYS {
LanguageLowerCase = '{lang}',
LanguageTitleCase = '{Lang}',
LanguageUpperCase = '{LANG}',
ExtensionLowerCase = '{file_extension}',
ExtensionUpperCase = '{FILE_EXTENSION}',
TotalLines = '{total_lines}',
CurrentLine = '{current_line}',
CurrentColumn = '{current_column}',
Expand Down