mirror of
https://github.com/kristoferssolo/solorice.git
synced 2025-10-21 20:10:34 +00:00
49 lines
1.9 KiB
JavaScript
49 lines
1.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.createPathCompletionItem = void 0;
|
|
const vscode = require("vscode");
|
|
function createPathCompletionItem(fileInfo, config, context) {
|
|
return fileInfo.isFile
|
|
? createFileItem(fileInfo, config, context)
|
|
: createFolderItem(fileInfo, config.autoSlash, config.autoTrigger, context.importRange);
|
|
}
|
|
exports.createPathCompletionItem = createPathCompletionItem;
|
|
function createFolderItem(fileInfo, autoSlash, autoTrigger, importRange) {
|
|
var newText = autoSlash || autoTrigger ? `${fileInfo.file}/` : `${fileInfo.file}`;
|
|
return {
|
|
label: fileInfo.file,
|
|
kind: vscode.CompletionItemKind.Folder,
|
|
sortText: `a_${fileInfo.file}`,
|
|
range: importRange,
|
|
insertText: newText,
|
|
command: autoTrigger
|
|
? {
|
|
title: "Trigger suggest",
|
|
command: "editor.action.triggerSuggest",
|
|
}
|
|
: undefined,
|
|
};
|
|
}
|
|
function createFileItem(fileInfo, config, context) {
|
|
const insertText = createCompletionItemInsertText(fileInfo, config, context);
|
|
return {
|
|
label: fileInfo.file,
|
|
kind: vscode.CompletionItemKind.File,
|
|
sortText: `b_${fileInfo.file}`,
|
|
range: context.importRange,
|
|
insertText: insertText,
|
|
};
|
|
}
|
|
function createCompletionItemInsertText(fileInfo, config, context) {
|
|
const shouldExcludeDocumentExtension = context.isImport &&
|
|
!config.withExtension &&
|
|
fileInfo.documentExtension === context.documentExtension;
|
|
return shouldExcludeDocumentExtension
|
|
? getFileNameWithoutExtension(fileInfo.file)
|
|
: fileInfo.file;
|
|
}
|
|
function getFileNameWithoutExtension(fileName) {
|
|
let index = fileName.lastIndexOf(".");
|
|
return index !== -1 ? fileName.substring(0, index) : fileName;
|
|
}
|
|
//# sourceMappingURL=createCompletionItem.js.map
|