|
| 1 | +/** |
| 2 | + * Main application entry point |
| 3 | + * @module main |
| 4 | + */ |
| 5 | + |
| 6 | +import { calculateAll, processUser, getServerConfig } from './helpers.js'; |
| 7 | +import { User, config } from './utils.js'; |
| 8 | + |
| 9 | +/** |
| 10 | + * Initializes the application with given parameters |
| 11 | + * @param {Object} options - Application options |
| 12 | + * @param {number} options.initialValue - Starting value |
| 13 | + * @param {string} options.userName - Default user name |
| 14 | + * @returns {Object} Initialized application state |
| 15 | + */ |
| 16 | +function initializeApp(options = {}) { |
| 17 | + const { initialValue = 10, userName = 'Guest' } = options; |
| 18 | + |
| 19 | + // Test code completion for imported functions |
| 20 | + const calculations = calculateAll(initialValue, 5); |
| 21 | + |
| 22 | + // Test code completion for imported class |
| 23 | + const defaultUser = new User(userName, 25); |
| 24 | + const userProfile = defaultUser.getProfile(); |
| 25 | + |
| 26 | + // Test code completion for nested imported object properties |
| 27 | + const serverPort = config.server.port; |
| 28 | + const dbSettings = config.database; |
| 29 | + |
| 30 | + // Test code completion for functions from helpers |
| 31 | + const serverConfig = getServerConfig(); |
| 32 | + |
| 33 | + // Process user data using helpers |
| 34 | + const processedData = processUser(userName, 30); |
| 35 | + |
| 36 | + return { |
| 37 | + initValue: initialValue, |
| 38 | + calculations, |
| 39 | + userProfile, |
| 40 | + serverInfo: { |
| 41 | + port: serverPort, |
| 42 | + settings: serverConfig.settings |
| 43 | + }, |
| 44 | + database: dbSettings, |
| 45 | + processedData |
| 46 | + }; |
| 47 | +} |
| 48 | + |
| 49 | +/** |
| 50 | + * Runs the application with specific settings |
| 51 | + * @param {string} mode - Application mode ('development' or 'production') |
| 52 | + */ |
| 53 | +function runApp(mode = 'development') { |
| 54 | + console.log(`Starting application in ${mode} mode`); |
| 55 | + |
| 56 | + const state = initializeApp({ |
| 57 | + initialValue: 20, |
| 58 | + userName: 'TestUser' |
| 59 | + }); |
| 60 | + |
| 61 | + console.log('Application initialized with state:', state); |
| 62 | + |
| 63 | + // Create a scenario to test peek definition |
| 64 | + // You should be able to peek at the definition of these imported items |
| 65 | + const userData = processUser('Alice', 22); |
| 66 | + getServerConfig(); |
| 67 | + |
| 68 | + // This line tests dot notation completion for multiple levels |
| 69 | + const timeout = config.server.settings.timeout; |
| 70 | + |
| 71 | + console.log('User data:', userData); |
| 72 | + console.log('Server timeout:', timeout); |
| 73 | +} |
| 74 | + |
| 75 | +// Call the main function to run the application |
| 76 | +runApp(); |
| 77 | + |
| 78 | +// Export for testing or importing elsewhere |
| 79 | +export { initializeApp, runApp }; |
0 commit comments