Skip to content
Open
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
92 changes: 92 additions & 0 deletions check-lsp-ready.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env node
/**
* Quick check script to verify TypeScript LSP is ready
* Run: node check-lsp-ready.js
*/

const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

console.log('╔════════════════════════════════════════════════════════════╗');
console.log('║ TypeScript LSP Integration - Readiness Check ║');
console.log('╚════════════════════════════════════════════════════════════╝\n');

let allGood = true;

// Check 1: LSP Infrastructure Enabled
console.log('1. LSP Infrastructure');
const clientLoaderPath = './src/languageTools/ClientLoader.js';
const clientLoaderContent = fs.readFileSync(clientLoaderPath, 'utf8');
const lspEnabled = clientLoaderContent.includes('initDomainAndHandleNodeCrash();') &&
!clientLoaderContent.includes('//initDomainAndHandleNodeCrash();');
console.log(' Status:', lspEnabled ? '✓ Enabled' : '✗ Disabled');
if (!lspEnabled) allGood = false;

// Check 2: Extension Registered
console.log('\n2. TypeScriptLanguageServer Extension');
const extensionsPath = './src/extensions/default/DefaultExtensions.json';
const extensionsContent = fs.readFileSync(extensionsPath, 'utf8');
const registered = extensionsContent.includes('"TypeScriptLanguageServer"');
console.log(' Registered:', registered ? '✓ Yes' : '✗ No');
if (!registered) allGood = false;

// Check 3: Extension Files
console.log('\n3. Extension Files');
const mainJs = './src/extensions/default/TypeScriptLanguageServer/main.js';
const clientJs = './src/extensions/default/TypeScriptLanguageServer/client.js';
console.log(' main.js:', fs.existsSync(mainJs) ? '✓ Exists' : '✗ Missing');
console.log(' client.js:', fs.existsSync(clientJs) ? '✓ Exists' : '✗ Missing');
if (!fs.existsSync(mainJs) || !fs.existsSync(clientJs)) allGood = false;

// Check 4: TypeScript Language Server
console.log('\n4. TypeScript Language Server');
const serverPath = './node_modules/.bin/typescript-language-server';
const serverExists = fs.existsSync(serverPath);
console.log(' Installed:', serverExists ? '✓ Yes' : '✗ No');

if (serverExists) {
try {
const version = execSync(serverPath + ' --version', { encoding: 'utf8' }).trim();
console.log(' Version:', version);
} catch (err) {
console.log(' Version: ✗ Cannot execute');
allGood = false;
}
} else {
allGood = false;
}

// Check 5: Client Path Resolution
console.log('\n5. Path Resolution in client.js');
const clientContent = fs.readFileSync(clientJs, 'utf8');
const hasCorrectPath = clientContent.includes('../../../../node_modules/.bin/typescript-language-server');
console.log(' Path:', hasCorrectPath ? '✓ Correct (4 levels up)' : '✗ Wrong');
if (!hasCorrectPath) allGood = false;

// Check 6: Simulate Path Resolution
console.log('\n6. Path Resolution Test');
const clientDir = path.dirname(path.resolve(clientJs));
const resolvedPath = path.resolve(clientDir, '../../../../node_modules/.bin/typescript-language-server');
const pathCorrect = fs.existsSync(resolvedPath);
console.log(' From:', clientDir);
console.log(' To:', resolvedPath);
console.log(' Valid:', pathCorrect ? '✓ Yes' : '✗ No');
if (!pathCorrect) allGood = false;

// Summary
console.log('\n' + '═'.repeat(60));
if (allGood) {
console.log('✓✓✓ ALL CHECKS PASSED ✓✓✓');
console.log('\nTypeScript LSP is ready! To test:');
console.log(' 1. npm run serve');
console.log(' 2. Open http://localhost:8000/src in browser');
console.log(' 3. Check browser console for initialization messages');
console.log(' 4. Open a .js file and test code completion');
} else {
console.log('✗✗✗ SOME CHECKS FAILED ✗✗✗');
console.log('\nPlease fix the issues above before testing.');
}
console.log('═'.repeat(60));

process.exit(allGood ? 0 : 1);
56 changes: 47 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
"requirejs": "^2.3.7",
"tern": "^0.24.3",
"tinycolor2": "^1.4.2",
"typescript": "^5.9.3",
"typescript-language-server": "^5.1.1",
"underscore": "^1.13.4"
}
}
1 change: 1 addition & 0 deletions src/extensions/default/DefaultExtensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"QuickView",
"SVGCodeHints",
"UrlCodeHints",
"TypeScriptLanguageServer",
"HealthData"
],
"desktopOnly": [
Expand Down
83 changes: 83 additions & 0 deletions src/extensions/default/TypeScriptLanguageServer/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2025 - present core.ai . All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

/*eslint-env es6, node*/
/*eslint max-len: ["error", { "code": 200 }]*/

/**
* TypeScript Language Server Client (Node.js side)
*
* ARCHITECTURE NOTE:
* Phoenix runs in the browser, but this file runs in Node.js via Phoenix's NodeDomain.
* Flow: Browser (main.js) → NodeDomain → Node.js (this file) → TypeScript LSP server
*
* This file:
* 1. Runs in a Node.js process spawned by Phoenix's NodeConnection
* 2. Creates a LanguageClient to manage the TypeScript language server
* 3. Spawns the actual typescript-language-server as a child process
* 4. Bridges LSP protocol between Phoenix (browser) and the language server (Node.js)
*/

var LanguageClient = require(global.LanguageClientInfo.languageClientPath).LanguageClient,
path = require("path"),
clientName = "TypeScriptLanguageServer",
client = null;

function getServerOptions() {
// Path to the typescript-language-server executable
// Go from: src/extensions/default/TypeScriptLanguageServer/ to project root
var serverPath = path.resolve(__dirname, "../../../../node_modules/.bin/typescript-language-server");

var serverOptions = {
command: serverPath,
args: ["--stdio"]
};

return serverOptions;
}

function setOptions(params) {
var options = {
serverOptions: getServerOptions(),
initializationOptions: {
preferences: {
// Enable all TypeScript/JavaScript features
includeCompletionsForModuleExports: true,
includeCompletionsWithInsertText: true,
importModuleSpecifierPreference: "relative",
allowIncompleteCompletions: true
}
}
};

client.setOptions(options);

return Promise.resolve("TypeScript Language Server options set successfully");
}

function init(domainManager) {
client = new LanguageClient(clientName, domainManager);
client.addOnRequestHandler('setOptions', setOptions);
}

exports.init = init;
93 changes: 93 additions & 0 deletions src/extensions/default/TypeScriptLanguageServer/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2025 - present core.ai . All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

/*eslint max-len: ["error", { "code": 200 }]*/
define(function (require, exports, module) {

var LanguageTools = brackets.getModule("languageTools/LanguageTools"),
AppInit = brackets.getModule("utils/AppInit"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
PreferencesManager = brackets.getModule("preferences/PreferencesManager");

var clientFilePath = ExtensionUtils.getModulePath(module, "client.js"),
clientName = "TypeScriptLanguageServer",
clientPromise = null,
client = null;

// Preference to enable/disable TypeScript/JavaScript LSP
PreferencesManager.definePreference("languageTools.enableTypeScriptLSP", "boolean", true, {
description: "Enable TypeScript/JavaScript Language Server Protocol support for enhanced code intelligence"
});

function isLSPEnabled() {
return PreferencesManager.get("languageTools.enableTypeScriptLSP");
}

AppInit.appReady(function () {
if (!isLSPEnabled()) {
console.log("TypeScript LSP is disabled via preferences");
return;
}

console.log("Initializing TypeScript Language Server...");

// Initialize the TypeScript/JavaScript language client
// Support both JavaScript and TypeScript files
clientPromise = LanguageTools.initiateToolingService(
clientName,
clientFilePath,
['javascript', 'typescript', 'jsx', 'tsx']
);

clientPromise.done(function (languageClient) {
client = languageClient;

// Send custom request to set options
client.sendCustomRequest({
messageType: "brackets",
type: "setOptions"
}).then(function (response) {
console.log("TypeScript Language Server initialized successfully:", response);
}).catch(function (err) {
console.error("Failed to set TypeScript Language Server options:", err);
});

}).fail(function (err) {
console.error("Failed to initialize TypeScript Language Server:", err);
});
});

// Listen for preference changes
PreferencesManager.on("change", "languageTools.enableTypeScriptLSP", function () {
var enabled = isLSPEnabled();
if (enabled && !client) {
console.log("TypeScript LSP enabled - restart Phoenix to activate");
} else if (!enabled && client) {
console.log("TypeScript LSP disabled - restart Phoenix to deactivate");
}
});

exports.getClient = function () {
return client;
};
});
11 changes: 11 additions & 0 deletions src/extensions/default/TypeScriptLanguageServer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "phcode-typescript-lsp",
"title": "TypeScript/JavaScript Language Server",
"version": "1.0.0",
"engines": {
"brackets": ">=4.0.0"
},
"description": "TypeScript/JavaScript Language Server Protocol integration for code intelligence features",
"nodeIsRequired": true,
"dependencies": {}
}
Loading
Loading