New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

typescript-language-server

Package Overview
Dependencies
Maintainers
3
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-language-server - npm Package Compare versions

Comparing version 0.6.4 to 0.6.5

10

CHANGELOG.md
# Changelog
All notable changes to this project will be documented in this file.
## [0.6.5] - 2021-11-03
- fix: normalize client and tsserver paths (#275)
This should ensure consistent behavior regradless of the platform. Previously some functionality could be malfunctioning on Windows depending on the LSP client used due to using non-normalized file paths.
- Handle the `APPLY_COMPLETION_CODE_ACTION` command internally (#270)
This means that the clients that have implemented a custom handling for the `_typescript.applyCompletionCodeAction` command can remove that code.
Without removing the custom handling everything should work as before but some edge cases might work better when custom handling is removed.
- fix: ignore empty code blocks in content returned from `textDocument/hover` (#276)
- fix: remove unsupported --node-ipc and --socket options (#278)
## [0.6.4] - 2021-10-12

@@ -5,0 +15,0 @@

8

lib/cli.js

@@ -36,6 +36,4 @@ #!/usr/bin/env node

.version(require('../package.json').version)
.option('--stdio', 'use stdio')
.option('--node-ipc', 'use node-ipc')
.requiredOption('--stdio', 'use stdio')
.option('--log-level <logLevel>', 'A number indicating the log level (4 = log, 3 = info, 2 = warn, 1 = error). Defaults to `2`.')
.option('--socket <port>', 'use socket. example: --socket=5000')
.option('--tsserver-log-file <tsserverLogFile>', 'Specify a tsserver log file. example: --tsserver-log-file ts-logs.txt')

@@ -47,6 +45,2 @@ .option('--tsserver-log-verbosity <tsserverLogVerbosity>', 'Specify a tsserver log verbosity (terse, normal, verbose). Defaults to `normal`.' +

const options = program.opts();
if (!(options.stdio || options.socket || options.nodeIpc)) {
console.error('Connection type required (stdio, node-ipc, socket). Refer to --help for more details.');
process.exit(1);
}
if (options.tsserverLogFile && !options.tsserverLogVerbosity) {

@@ -53,0 +47,0 @@ options.tsserverLogVerbosity = 'normal';

@@ -7,6 +7,6 @@ export declare const Commands: {

APPLY_RENAME_FILE: string;
APPLY_COMPLETION_CODE_ACTION: string;
/** Commands below should be implemented by the client */
APPLY_COMPLETION_CODE_ACTION: string;
SELECT_REFACTORING: string;
};
//# sourceMappingURL=commands.d.ts.map

@@ -16,6 +16,6 @@ "use strict";

APPLY_RENAME_FILE: '_typescript.applyRenameFile',
APPLY_COMPLETION_CODE_ACTION: '_typescript.applyCompletionCodeAction',
/** Commands below should be implemented by the client */
APPLY_COMPLETION_CODE_ACTION: '_typescript.applyCompletionCodeAction',
SELECT_REFACTORING: '_typescript.selectRefactoring'
};
//# sourceMappingURL=commands.js.map

@@ -166,21 +166,17 @@ "use strict";

function asResolvedCompletionItem(item, details) {
var _a;
item.detail = asDetail(details);
item.documentation = (0, protocol_translation_1.asDocumentation)(details);
Object.assign(item, asCodeActions(details, item.data.file));
if ((_a = details.codeActions) === null || _a === void 0 ? void 0 : _a.length) {
const filepath = (0, protocol_translation_1.normalizePath)(item.data.file);
item.additionalTextEdits = asAdditionalTextEdits(details.codeActions, filepath);
item.command = asCommand(details.codeActions, item.data.file);
}
return item;
}
exports.asResolvedCompletionItem = asResolvedCompletionItem;
function asCodeActions(details, filepath) {
if (!details.codeActions || !details.codeActions.length) {
return {};
}
function asAdditionalTextEdits(codeActions, filepath) {
// Try to extract out the additionalTextEdits for the current file.
// Also check if we still have to apply other workspace edits and commands
// using a vscode command
const additionalTextEdits = [];
let hasRemainingCommandsOrEdits = false;
for (const tsAction of details.codeActions) {
if (tsAction.commands) {
hasRemainingCommandsOrEdits = true;
}
for (const tsAction of codeActions) {
// Apply all edits in the current file using `additionalTextEdits`

@@ -194,4 +190,19 @@ if (tsAction.changes) {

}
else {
}
}
}
return additionalTextEdits.length ? additionalTextEdits : undefined;
}
function asCommand(codeActions, filepath) {
let hasRemainingCommandsOrEdits = false;
for (const tsAction of codeActions) {
if (tsAction.commands) {
hasRemainingCommandsOrEdits = true;
break;
}
if (tsAction.changes) {
for (const change of tsAction.changes) {
if (change.fileName !== filepath) {
hasRemainingCommandsOrEdits = true;
break;
}

@@ -201,9 +212,8 @@ }

}
let command = undefined;
if (hasRemainingCommandsOrEdits) {
// Create command that applies all edits not in the current file.
command = {
return {
title: '',
command: commands_1.Commands.APPLY_COMPLETION_CODE_ACTION,
arguments: [filepath, details.codeActions.map(codeAction => ({
arguments: [filepath, codeActions.map(codeAction => ({
commands: codeAction.commands,

@@ -215,6 +225,2 @@ description: codeAction.description,

}
return {
command,
additionalTextEdits: additionalTextEdits.length ? additionalTextEdits : undefined
};
}

@@ -221,0 +227,0 @@ function asDetail({ displayParts, sourceDisplay, source: deprecatedSource }) {

@@ -52,2 +52,24 @@ "use strict";

});
describe('completions', () => {
it('receives completion that auto-imports from another module', () => __awaiter(void 0, void 0, void 0, function* () {
const doc = {
uri: (0, test_utils_1.uri)('completion.ts'),
languageId: 'typescript',
version: 1,
text: (0, test_utils_1.readContents)((0, test_utils_1.filePath)('completion.ts'))
};
server.didOpenTextDocument({ textDocument: doc });
const proposals = yield server.completion({
textDocument: doc,
position: (0, test_utils_1.positionAfter)(doc, 'doStuff')
});
assert.isNotNull(proposals);
const completion = proposals.items.find(item => item.label === 'doStuff');
assert.isDefined(completion);
const resolvedCompletion = yield server.completionResolve(completion);
assert.isDefined(resolvedCompletion.additionalTextEdits);
assert.isUndefined(resolvedCompletion.command);
server.didCloseTextDocument({ textDocument: doc });
})).timeout(10000);
});
//# sourceMappingURL=file-lsp-server.spec.js.map

@@ -494,5 +494,6 @@ "use strict";

const range = (0, protocol_translation_1.asRange)(result.body);
const contents = [
{ language: 'typescript', value: result.body.displayString }
];
const contents = [];
if (result.body.displayString) {
contents.push({ language: 'typescript', value: result.body.displayString });
}
const tags = (0, protocol_translation_1.asTagsDocumentation)(result.body.tags);

@@ -781,2 +782,15 @@ const documentation = (0, protocol_translation_1.asPlainText)(result.body.documentation);

}
else if (arg.command === commands_1.Commands.APPLY_COMPLETION_CODE_ACTION && arg.arguments) {
const [_, codeActions] = arg.arguments;
for (const codeAction of codeActions) {
yield this.applyFileCodeEdits(codeAction.changes);
if (codeAction.commands && codeAction.commands.length) {
for (const command of codeAction.commands) {
yield this.tspClient.request("applyCodeActionCommand" /* ApplyCodeActionCommand */, { command });
}
}
// Execute only the first code action.
break;
}
}
else {

@@ -853,3 +867,3 @@ this.logger.error(`Unknown command ${arg.command}.`);

// Converting to a URI and back to a path ensures consistency.
if ((0, protocol_translation_1.uriToPath)((0, protocol_translation_1.pathToUri)(item.file, this.documents)) === file) {
if ((0, protocol_translation_1.normalizePath)(item.file) === file) {
const highlights = (0, protocol_translation_1.toDocumentHighlight)(item);

@@ -856,0 +870,0 @@ result.push(...highlights);

@@ -37,5 +37,5 @@ "use strict";

}
return response.body.map(edit => lsp.CodeAction.create('Organize imports', lsp.Command.create('', commands_1.Commands.ORGANIZE_IMPORTS, (0, protocol_translation_1.normalizeFileNameToFsPath)(edit.fileName)), node_1.CodeActionKind.SourceOrganizeImports));
return response.body.map(edit => lsp.CodeAction.create('Organize imports', lsp.Command.create('', commands_1.Commands.ORGANIZE_IMPORTS, (0, protocol_translation_1.normalizePath)(edit.fileName)), node_1.CodeActionKind.SourceOrganizeImports));
}
exports.provideOrganizeImports = provideOrganizeImports;
//# sourceMappingURL=organize-imports.js.map

@@ -11,6 +11,10 @@ import * as lsp from 'vscode-languageserver/node';

*
* On Windows, an input path in a format like "c:/path/file.ts"
* will be normalized to "c:\path\file.ts" (same as returned through URI.fsPath).
* On Windows, an input path in a format like "C:/path/file.ts"
* will be normalized to "c:/path/file.ts".
*/
export declare function normalizeFileNameToFsPath(fileName: string): string;
export declare function normalizePath(filePath: string): string;
/**
* Normalizes the path obtained through the "fsPath" property of the URI module.
*/
export declare function normalizeFsPath(fsPath: string): string;
export declare function toPosition(location: tsp.Location): lsp.Position;

@@ -17,0 +21,0 @@ export declare function toLocation(fileSpan: tsp.FileSpan, documents: LspDocuments | undefined): lsp.Location;

@@ -31,5 +31,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Range = exports.asPlainText = exports.asTagBodyText = exports.asTagDocumentation = exports.asTagsDocumentation = exports.asDocumentation = exports.asRange = exports.toDocumentHighlight = exports.toTextDocumentEdit = exports.toTextEdit = exports.toDiagnostic = exports.toSymbolKind = exports.toFileRangeRequestArgs = exports.toLocation = exports.toPosition = exports.normalizeFileNameToFsPath = exports.pathToUri = exports.uriToPath = void 0;
exports.Range = exports.asPlainText = exports.asTagBodyText = exports.asTagDocumentation = exports.asTagsDocumentation = exports.asDocumentation = exports.asRange = exports.toDocumentHighlight = exports.toTextDocumentEdit = exports.toTextEdit = exports.toDiagnostic = exports.toSymbolKind = exports.toFileRangeRequestArgs = exports.toLocation = exports.toPosition = exports.normalizeFsPath = exports.normalizePath = exports.pathToUri = exports.uriToPath = void 0;
const lsp = __importStar(require("vscode-languageserver/node"));
const vscode_uri_1 = __importDefault(require("vscode-uri"));
const RE_PATHSEP_WINDOWS = /\\/g;
function uriToPath(stringUri) {

@@ -40,3 +41,3 @@ const uri = vscode_uri_1.default.parse(stringUri);

}
return uri.fsPath;
return normalizeFsPath(uri.fsPath);
}

@@ -55,3 +56,4 @@ exports.uriToPath = uriToPath;

const fileUri = parsePathOrUri(filepath);
const document = documents && documents.get(fileUri.fsPath);
const normalizedFilepath = normalizePath(fileUri.fsPath);
const document = documents && documents.get(normalizedFilepath);
return document ? document.uri : fileUri.toString();

@@ -65,12 +67,21 @@ }

*
* On Windows, an input path in a format like "c:/path/file.ts"
* will be normalized to "c:\path\file.ts" (same as returned through URI.fsPath).
* On Windows, an input path in a format like "C:/path/file.ts"
* will be normalized to "c:/path/file.ts".
*/
function normalizeFileNameToFsPath(fileName) {
return vscode_uri_1.default.file(fileName).fsPath;
function normalizePath(filePath) {
const fsPath = vscode_uri_1.default.file(filePath).fsPath;
return normalizeFsPath(fsPath);
}
exports.normalizeFileNameToFsPath = normalizeFileNameToFsPath;
exports.normalizePath = normalizePath;
/**
* Normalizes the path obtained through the "fsPath" property of the URI module.
*/
function normalizeFsPath(fsPath) {
return fsPath.replace(RE_PATHSEP_WINDOWS, '/');
}
exports.normalizeFsPath = normalizeFsPath;
function currentVersion(filepath, documents) {
const fileUri = vscode_uri_1.default.file(filepath);
const document = documents && documents.get(fileUri.fsPath);
const normalizedFilepath = normalizePath(fileUri.fsPath);
const document = documents && documents.get(normalizedFilepath);
return document ? document.version : 0;

@@ -77,0 +88,0 @@ }

@@ -71,3 +71,3 @@ "use strict";

function filePath(suffix = '') {
return (0, protocol_translation_1.normalizeFileNameToFsPath)(path.resolve(__dirname, '../test-data', suffix));
return (0, protocol_translation_1.normalizePath)(path.resolve(__dirname, '..', 'test-data', suffix));
}

@@ -74,0 +74,0 @@ exports.filePath = filePath;

@@ -79,11 +79,17 @@ "use strict";

: cp.spawn(tsserverPath, args);
this.readlineInterface = readline.createInterface(this.tsserverProc.stdout, this.tsserverProc.stdin, undefined);
process.on('exit', () => {
this.readlineInterface.close();
this.tsserverProc.stdin.destroy();
var _a, _b;
(_a = this.readlineInterface) === null || _a === void 0 ? void 0 : _a.close();
(_b = this.tsserverProc.stdin) === null || _b === void 0 ? void 0 : _b.destroy();
this.tsserverProc.kill();
});
const { stdout, stdin, stderr } = this.tsserverProc;
if (!stdout || !stdin || !stderr) {
this.logger.error(`Failed initializing input/output of tsserver (stdin: ${!!stdin}, stdout: ${!!stdout}, stderr: ${!!stderr})`);
process.exit(1);
}
this.readlineInterface = readline.createInterface(stdout, stdin, undefined);
this.readlineInterface.on('line', line => this.processMessage(line));
const dec = new decoder.StringDecoder('utf-8');
this.tsserverProc.stderr.addListener('data', data => {
stderr.addListener('data', data => {
const stringMsg = typeof data === 'string' ? data : dec.write(data);

@@ -90,0 +96,0 @@ this.tsserverLogger.error(stringMsg);

{
"name": "typescript-language-server",
"version": "0.6.4",
"version": "0.6.5",
"description": "Language Server Protocol (LSP) implementation for TypeScript using tsserver",

@@ -40,6 +40,6 @@ "author": "TypeFox and others",

"devDependencies": {
"@types/chai": "^4.2.19",
"@types/fs-extra": "^9.0.11",
"@types/chai": "^4.2.19",
"@types/mocha": "^8.2.2",
"@types/node": "^8.0.31",
"@types/mocha": "^9.0.0",
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "^4.28.0",

@@ -46,0 +46,0 @@ "@typescript-eslint/parser": "^4.28.0",

@@ -35,6 +35,4 @@ [![Build Status](https://travis-ci.org/theia-ide/typescript-language-server.svg?branch=master)](https://travis-ci.org/theia-ide/typescript-language-server)

-V, --version output the version number
--stdio use stdio
--node-ipc use node-ipc
--stdio use stdio (the only supported and required option)
--log-level <log-level> A number indicating the log level (4 = log, 3 = info, 2 = warn, 1 = error). Defaults to `2`.
--socket <port> use socket. example: --socket=5000
--tsserver-log-file <tsServerLogFile> Specify a tsserver log file. example: --tsserver-log-file=ts-logs.txt

@@ -41,0 +39,0 @@ --tsserver-log-verbosity <verbosity> Specify tsserver log verbosity (off, terse, normal, verbose). Defaults to `normal`. example: --tsserver-log-verbosity=verbose

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc