Skip to content

Commit a0a1543

Browse files
committed
lsp.js working
1 parent 01bd486 commit a0a1543

File tree

9 files changed

+2250
-2
lines changed

9 files changed

+2250
-2
lines changed

package-lock.json

Lines changed: 71 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"mocha": "10.3.0"
5959
},
6060
"dependencies": {
61-
"typescript": "5.4.2"
61+
"typescript": "^5.4.2",
62+
"typescript-language-server": "^4.3.4",
63+
"vscode-languageserver-protocol": "^3.17.5",
64+
"vscode-uri": "^3.1.0"
6265
}
6366
}

src/test/baseJS/helpers.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Helper functions that depend on utils module
3+
* @module helpers
4+
*/
5+
6+
import { add, subtract, User, config } from './utils.js';
7+
8+
/**
9+
* Multiplies two numbers
10+
* @param {number} a - First number to multiply
11+
* @param {number} b - Second number to multiply
12+
* @returns {number} The product of a and b
13+
*/
14+
export function multiply(a, b) {
15+
return a * b;
16+
}
17+
18+
/**
19+
* Performs multiple arithmetic operations
20+
* @param {number} x - First operand
21+
* @param {number} y - Second operand
22+
* @returns {Object} Object containing results of various operations
23+
*/
24+
export function calculateAll(x, y) {
25+
return {
26+
sum: add(x, y),
27+
difference: subtract(x, y),
28+
product: multiply(x, y),
29+
quotient: x / y
30+
};
31+
}
32+
33+
/**
34+
* Creates and processes user data
35+
* @param {string} name - User name
36+
* @param {number} age - User age
37+
* @returns {Object} Processed user data
38+
*/
39+
export function processUser(name, age) {
40+
const user = new User(name, age);
41+
42+
return {
43+
profile: user.getProfile(),
44+
isAdult: user.isAdult(),
45+
nameLength: name.length,
46+
serverConfig: config.server
47+
};
48+
}
49+
50+
/**
51+
* @typedef {Object} ServerOptions
52+
* @property {number} port - Server port
53+
* @property {string} host - Server hostname
54+
* @property {Object} settings - Additional settings
55+
*/
56+
57+
/**
58+
* Gets server configuration from utils
59+
* @returns {ServerOptions} Server configuration options
60+
*/
61+
export function getServerConfig() {
62+
return config.server;
63+
}
64+
65+
// Non-exported function for testing internal visibility
66+
/**
67+
* Internal helper function not exported
68+
* @param {string} str - String to process
69+
* @returns {string} Processed string
70+
* @private
71+
*/
72+
function internalHelper(str) {
73+
return str.toUpperCase();
74+
}

src/test/baseJS/main.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 };

src/test/baseJS/temp-tsconfig.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"module": "NodeNext",
5+
"allowJs": true,
6+
"checkJs": true,
7+
"moduleResolution": "NodeNext",
8+
"esModuleInterop": true,
9+
"skipLibCheck": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"lib": [
12+
"ES2020",
13+
"DOM"
14+
]
15+
},
16+
"include": [
17+
"**/*.js",
18+
"**/*.jsx",
19+
"**/*.ts",
20+
"**/*.tsx",
21+
"**/*.mjs"
22+
],
23+
"exclude": [
24+
"node_modules",
25+
"dist"
26+
]
27+
}

src/test/baseJS/utils.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Utility functions module for testing language server features
3+
* @module utils
4+
*/
5+
6+
/**
7+
* Calculates the sum of two numbers
8+
* @param {number} a - First number to add
9+
* @param {number} b - Second number to add
10+
* @returns {number} The sum of a and b
11+
*/
12+
export function add(a, b) {
13+
return a + b;
14+
}
15+
16+
/**
17+
* Calculates the difference between two numbers
18+
* @param {number} a - Number to subtract from
19+
* @param {number} b - Number to subtract
20+
* @returns {number} The difference between a and b
21+
*/
22+
export function subtract(a, b) {
23+
return a - b;
24+
}
25+
26+
/**
27+
* User class for testing complex type definitions
28+
* @class
29+
*/
30+
export class User {
31+
/**
32+
* Create a user
33+
* @param {string} name - The user's name
34+
* @param {number} age - The user's age
35+
*/
36+
constructor(name, age) {
37+
this.name = name;
38+
this.age = age;
39+
}
40+
41+
/**
42+
* Get user's full profile information
43+
* @returns {Object} User profile object
44+
*/
45+
getProfile() {
46+
return {
47+
name: this.name,
48+
age: this.age,
49+
createdAt: new Date()
50+
};
51+
}
52+
53+
/**
54+
* Check if user is an adult
55+
* @returns {boolean} True if user is 18 or older
56+
*/
57+
isAdult() {
58+
return this.age >= 18;
59+
}
60+
}
61+
62+
/**
63+
* Object with nested properties for testing dot notation completion
64+
*/
65+
export const config = {
66+
server: {
67+
port: 3000,
68+
host: 'localhost',
69+
settings: {
70+
timeout: 5000,
71+
maxConnections: 100
72+
}
73+
},
74+
database: {
75+
url: 'mongodb://localhost:27017',
76+
name: 'testdb'
77+
}
78+
};

0 commit comments

Comments
 (0)