Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function quickTabSwitch(type) {
const state = getState();
const openedFiles = Array.from(state.project.openedFiles.values());
if (openedFiles.length === 1) {
// We can't switch to any other file, there's only one
return;
}
const currentFile = state.session.currentFile.filePath;
let fileToFallbackTo;
let currentFileIndex = -1;
for (let i = 0; i < openedFiles.length; i++) {
if (openedFiles[i].filePath === currentFile) {
currentFileIndex = i;
}
}
cancelQuestion = () => {
getState().session.editor.focus();
this.setState({ ...initialState });
};
export default function fileTreePlugin(input) {
const state = getState();
const suggestions = [];
input = input.toLowerCase();
const openedFiles = Array.from(state.project.openedFiles.values());
for (const filePath of FileTreeManager.getAllFilePaths()) {
if (filePath.toLowerCase().includes(input)) {
const priority = _priorityForFile(filePath, openedFiles);
const searchSuggestion = new SearchSuggestion({
type: 'file',
title: path.basename(filePath),
description: path.dirname(filePath),
select: () => {
const fullFilePath = path.join(state.project.cwd, filePath);
dispatch.session.openFileAsync(fullFilePath);
},
priority,
get packageManager() {
return getState().project.packageManager;
}
getLocalSuggestions = () => {
const state = getState();
const currentFilePath = state.session.currentFile.filePath;
const from = currentFilePath.replace(state.project.cwd, '');
const filePaths = FileTreeManager.getAllFilePaths().filter(
filePath => !filePath.includes('node_modules')
);
let approvedSuggestions = [];
for (const to of filePaths) {
if (from && from !== to) {
let toFile = path.relative(from, to).substr(2);
if (toFile.substr(0, 3) !== '/..') {
toFile = '.' + toFile;
} else {
toFile = toFile.substr(1);
}
function switchPackageManager(type) {
const currentPackageManager = getState().project.packageManager;
let packageManager;
switch (type) {
default:
case SwitchPackageManager.NPM:
if (typeof currentPackageManager !== packageManagers.NpmPackageManager) {
packageManager = new packageManagers.NpmPackageManager();
}
break;
case SwitchPackageManager.YARN:
if (typeof currentPackageManager !== packageManagers.YarnPackageManager) {
packageManager = new packageManagers.YarnPackageManager();
}
break;
}
getCwd = () => getState().project.cwd;
format = async () => {
let options = await this.resolveConfig();
if (!options) options = await this.createConfigurationFile();
const editor = getState().session.editor;
const code = editor.getValue();
return prettier.format(code, options);
};
static get project() {
const state = getState();
return project(state.project, state);
}