Skip to content
Merged
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
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"cph.submit.notKattis": "Not a kattis problem.",
"cph.submit.notCodeforces": "Not a codeforces problem.",
"cph.utils.unsupported": "Unsupported file extension. Only these types are valid: {0}",
"cph.utils.noActiveEditor": "No active editor found.",
"cph.preferences.invalidSaveLocation": "Invalid save location, reverting to default. path not exists: {0}",
"cph.processRunSingle.invalidChecker": "Custom checker script not found at '{0}'"
}
1 change: 1 addition & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"cph.submit.notKattis": "不是 Kattis 题目。",
"cph.submit.notCodeforces": "不是 Codeforces 题目。",
"cph.utils.unsupported": "不支持的文件扩展名。只有以下类型有效:{0}",
"cph.utils.noActiveEditor": "未发现活动中的编辑器。",
"cph.preferences.invalidSaveLocation": "保存位置无效,正在恢复为默认值。路径不存在:{0}",
"cph.processRunSingle.invalidChecker": "在“{0}”处未找到自定义判题脚本"
}
20 changes: 16 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ const oc = vscode.window.createOutputChannel('cph');
* Get language based on file extension
*/
export const getLanguage = (srcPath: string): Language => {
const extension = path.extname(srcPath).split('.').pop();
const extension = path.extname(srcPath).toLowerCase().replace('.', '');
let langName: string | void = undefined;
for (const [lang, ext] of Object.entries(config.extensions)) {
if (ext === extension) {
langName = lang;
}
}

if (
langName === undefined &&
(config.extensions as any)[extension] !== undefined
) {
langName = extension;
}

if (langName === undefined) {
throw new Error('Invalid extension');
}
Expand Down Expand Up @@ -148,9 +155,8 @@ export const getLanguage = (srcPath: string): Language => {
};

export const isValidLanguage = (srcPath: string): boolean => {
return config.supportedExtensions.includes(
path.extname(srcPath).split('.')[1],
);
const ext = path.extname(srcPath).toLowerCase().replace('.', '');
return config.supportedExtensions.includes(ext);
};

export const isCodeforcesUrl = (url: URL): boolean => {
Expand Down Expand Up @@ -194,6 +200,12 @@ export const randomId = (index: number | null) => {
* unsupported.
*/
export const checkUnsupported = (srcPath: string): boolean => {
if (srcPath === '') {
vscode.window.showErrorMessage(
localize('cph.utils.noActiveEditor', 'No active editor found.'),
);
return true;
}
if (!isValidLanguage(srcPath)) {
vscode.window.showErrorMessage(
localize(
Expand Down
Loading