Skip to content

Commit 0d7081b

Browse files
committed
feat: integrate TypeScript language server for JavaScript/TypeScript LSP support
This commit adds full Language Server Protocol (LSP) support for JavaScript, TypeScript, JSX, and TSX files using the TypeScript language server. Changes: - Created TypeScriptLanguageServer extension in src/extensions/default/ - Installed typescript-language-server v5.1.1 and typescript dependencies - Registered extension in DefaultExtensions.json - Configured language server to use stdio communication Extension Components: 1. client.js (Node.js side) - Spawns typescript-language-server process - Configures server with --stdio communication - Sets up TypeScript preferences and initialization options 2. main.js (Phoenix/Brackets side) - Registers LSP client for ['javascript', 'typescript', 'jsx', 'tsx'] - Integrates with LanguageTools.initiateToolingService API - Provides preference to enable/disable: languageTools.enableTypeScriptLSP Features Enabled: - Intelligent code completion with IntelliSense - Parameter hints and signature help - Jump to definition/declaration/implementation - Find all references - Document symbols (outline) - Workspace symbols (project-wide search) - Real-time error detection and diagnostics - Rename refactoring - Auto-imports The TypeScript language server provides advanced TypeScript and JavaScript code intelligence, significantly enhancing the development experience for web developers using Phoenix.
1 parent ccb6935 commit 0d7081b

5 files changed

Lines changed: 211 additions & 9 deletions

File tree

package-lock.json

Lines changed: 47 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@
118118
"requirejs": "^2.3.7",
119119
"tern": "^0.24.3",
120120
"tinycolor2": "^1.4.2",
121+
"typescript": "^5.9.3",
122+
"typescript-language-server": "^5.1.1",
121123
"underscore": "^1.13.4"
122124
}
123125
}

src/extensions/default/DefaultExtensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"QuickView",
2424
"SVGCodeHints",
2525
"UrlCodeHints",
26+
"TypeScriptLanguageServer",
2627
"HealthData"
2728
],
2829
"desktopOnly": [
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2025 - present core.ai . All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
/*eslint-env es6, node*/
25+
/*eslint max-len: ["error", { "code": 200 }]*/
26+
27+
var LanguageClient = require(global.LanguageClientInfo.languageClientPath).LanguageClient,
28+
path = require("path"),
29+
clientName = "TypeScriptLanguageServer",
30+
client = null;
31+
32+
function getServerOptions() {
33+
// Path to the typescript-language-server executable
34+
var serverPath = path.resolve(__dirname, "../../../node_modules/.bin/typescript-language-server");
35+
36+
var serverOptions = {
37+
command: serverPath,
38+
args: ["--stdio"]
39+
};
40+
41+
return serverOptions;
42+
}
43+
44+
function setOptions(params) {
45+
var options = {
46+
serverOptions: getServerOptions(),
47+
initializationOptions: {
48+
preferences: {
49+
// Enable all TypeScript/JavaScript features
50+
includeCompletionsForModuleExports: true,
51+
includeCompletionsWithInsertText: true,
52+
importModuleSpecifierPreference: "relative",
53+
allowIncompleteCompletions: true
54+
}
55+
}
56+
};
57+
58+
client.setOptions(options);
59+
60+
return Promise.resolve("TypeScript Language Server options set successfully");
61+
}
62+
63+
function init(domainManager) {
64+
client = new LanguageClient(clientName, domainManager);
65+
client.addOnRequestHandler('setOptions', setOptions);
66+
}
67+
68+
exports.init = init;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2025 - present core.ai . All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
/*eslint max-len: ["error", { "code": 200 }]*/
25+
define(function (require, exports, module) {
26+
27+
var LanguageTools = brackets.getModule("languageTools/LanguageTools"),
28+
AppInit = brackets.getModule("utils/AppInit"),
29+
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
30+
PreferencesManager = brackets.getModule("preferences/PreferencesManager");
31+
32+
var clientFilePath = ExtensionUtils.getModulePath(module, "client.js"),
33+
clientName = "TypeScriptLanguageServer",
34+
clientPromise = null,
35+
client = null;
36+
37+
// Preference to enable/disable TypeScript/JavaScript LSP
38+
PreferencesManager.definePreference("languageTools.enableTypeScriptLSP", "boolean", true, {
39+
description: "Enable TypeScript/JavaScript Language Server Protocol support for enhanced code intelligence"
40+
});
41+
42+
function isLSPEnabled() {
43+
return PreferencesManager.get("languageTools.enableTypeScriptLSP");
44+
}
45+
46+
AppInit.appReady(function () {
47+
if (!isLSPEnabled()) {
48+
console.log("TypeScript LSP is disabled via preferences");
49+
return;
50+
}
51+
52+
console.log("Initializing TypeScript Language Server...");
53+
54+
// Initialize the TypeScript/JavaScript language client
55+
// Support both JavaScript and TypeScript files
56+
clientPromise = LanguageTools.initiateToolingService(
57+
clientName,
58+
clientFilePath,
59+
['javascript', 'typescript', 'jsx', 'tsx']
60+
);
61+
62+
clientPromise.done(function (languageClient) {
63+
client = languageClient;
64+
65+
// Send custom request to set options
66+
client.sendCustomRequest({
67+
messageType: "brackets",
68+
type: "setOptions"
69+
}).then(function (response) {
70+
console.log("TypeScript Language Server initialized successfully:", response);
71+
}).catch(function (err) {
72+
console.error("Failed to set TypeScript Language Server options:", err);
73+
});
74+
75+
}).fail(function (err) {
76+
console.error("Failed to initialize TypeScript Language Server:", err);
77+
});
78+
});
79+
80+
// Listen for preference changes
81+
PreferencesManager.on("change", "languageTools.enableTypeScriptLSP", function () {
82+
var enabled = isLSPEnabled();
83+
if (enabled && !client) {
84+
console.log("TypeScript LSP enabled - restart Phoenix to activate");
85+
} else if (!enabled && client) {
86+
console.log("TypeScript LSP disabled - restart Phoenix to deactivate");
87+
}
88+
});
89+
90+
exports.getClient = function () {
91+
return client;
92+
};
93+
});

0 commit comments

Comments
 (0)