Skip to content

Commit b63dd95

Browse files
authored
Add Windows and Mac CI runner (typescript-language-server#248)
1 parent 8fa6539 commit b63dd95

8 files changed

+33
-13
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Force LF line endings everywhere (especially for Windows CI)
2+
* text eol=lf

.github/workflows/ci.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ on:
1010
- master
1111

1212
jobs:
13-
build:
14-
runs-on: ubuntu-latest
15-
env:
16-
CI: true
13+
tests:
1714
strategy:
1815
matrix:
16+
os: [windows-latest, macos-latest, ubuntu-latest]
1917
node-version: [12.x, 14.x, 16.x]
20-
name: Use Node.js ${{ matrix.node-version }}
18+
runs-on: ${{ matrix.os }}
19+
env:
20+
CI: true
21+
name: ${{ matrix.os }} (Node.js ${{ matrix.node-version }})
2122
steps:
2223
- uses: actions/checkout@v2
2324
- name: Setup node

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"scripts": {
3232
"clean": "rimraf lib *.tsbuildinfo",
3333
"test": "mocha --exit --reporter spec \"./lib/**/*.spec.js\"",
34-
"lint": "eslint --ext '.js,.ts' src",
34+
"lint": "eslint --ext \".js,.ts\" src",
3535
"build": "concurrently -n compile,lint -c blue,green \"yarn compile\" \"yarn lint\"",
3636
"compile": "tsc -b",
3737
"watch": "tsc -b --watch --verbose"

src/organize-imports.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import tsp from 'typescript/lib/protocol';
22
import * as chai from 'chai';
33
import { provideOrganizeImports } from './organize-imports';
4+
import { filePath } from './test-utils';
45

56
describe('provideOrganizeImports', () => {
67
it('converts tsserver response to lsp code actions', () => {
8+
const fileName = filePath('file');
79
const response = {
810
body: [
911
{
10-
fileName: '/my/file',
12+
fileName,
1113
textChanges: []
1214
}
1315
]
@@ -19,7 +21,7 @@ describe('provideOrganizeImports', () => {
1921
command: {
2022
title: '',
2123
command: '_typescript.organizeImports',
22-
arguments: ['/my/file']
24+
arguments: [fileName]
2325
}
2426
}];
2527
chai.assert.deepEqual(actual, expected);

src/organize-imports.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import * as lsp from 'vscode-languageserver/node';
99
import tsp from 'typescript/lib/protocol';
1010
import { Commands } from './commands';
11+
import { normalizeFileNameToFsPath } from './protocol-translation';
1112
import { CodeActionKind } from 'vscode-languageserver/node';
1213

1314
export function provideOrganizeImports(response: tsp.OrganizeImportsResponse | undefined): Array<lsp.CodeAction> {
@@ -16,7 +17,7 @@ export function provideOrganizeImports(response: tsp.OrganizeImportsResponse | u
1617
}
1718
return response.body.map(edit => lsp.CodeAction.create(
1819
'Organize imports',
19-
lsp.Command.create('', Commands.ORGANIZE_IMPORTS, edit.fileName),
20+
lsp.Command.create('', Commands.ORGANIZE_IMPORTS, normalizeFileNameToFsPath(edit.fileName)),
2021
CodeActionKind.SourceOrganizeImports
2122
));
2223
}

src/protocol-translation.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ export function pathToUri(filepath: string, documents: LspDocuments | undefined)
3434
return document ? document.uri : fileUri.toString();
3535
}
3636

37+
/**
38+
* Normalizes the file system path.
39+
*
40+
* On systems other than Windows it should be an no-op.
41+
*
42+
* On Windows, an input path in a format like "c:/path/file.ts"
43+
* will be normalized to "c:\path\file.ts" (same as returned through URI.fsPath).
44+
*/
45+
export function normalizeFileNameToFsPath(fileName: string): string {
46+
return URI.file(fileName).fsPath;
47+
}
48+
3749
function currentVersion(filepath: string, documents: LspDocuments | undefined): number {
3850
const fileUri = URI.file(filepath);
3951
const document = documents && documents.get(fileUri.fsPath);

src/test-utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import * as path from 'path';
99
import * as fs from 'fs';
1010
import * as lsp from 'vscode-languageserver/node';
11-
import { pathToUri } from './protocol-translation';
11+
import { normalizeFileNameToFsPath, pathToUri } from './protocol-translation';
1212
import { LspServer } from './lsp-server';
1313
import { ConsoleLogger } from './logger';
14+
import { getTsserverExecutable } from './utils';
1415
import { TextDocument } from 'vscode-languageserver-textdocument';
1516

1617
export function getDefaultClientCapabilities(): lsp.ClientCapabilities {
@@ -38,7 +39,7 @@ export function uri(suffix = ''): string {
3839
}
3940

4041
export function filePath(suffix = ''): string {
41-
return path.resolve(__dirname, '../test-data', suffix);
42+
return normalizeFileNameToFsPath(path.resolve(__dirname, '../test-data', suffix));
4243
}
4344

4445
export function readContents(path: string): string {
@@ -75,7 +76,7 @@ export async function createServer(options: {
7576
const logger = new ConsoleLogger(false);
7677
const server = new LspServer({
7778
logger,
78-
tsserverPath: 'tsserver',
79+
tsserverPath: getTsserverExecutable(),
7980
tsserverLogVerbosity: options.tsserverLogVerbosity,
8081
tsserverLogFile: path.resolve(__dirname, '../tsserver.log'),
8182
lspClient: {

src/tsp-client.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import { ConsoleLogger } from './logger';
1212
import { filePath, readContents } from './test-utils';
1313
import { CommandTypes } from './tsp-command-types';
1414
import { findPathToModule } from './modules-resolver';
15+
import { getTsserverExecutable } from './utils';
1516

1617
const assert = chai.assert;
1718

1819
const executableServer = new TspClient({
1920
logger: new ConsoleLogger(),
20-
tsserverPath: 'tsserver'
21+
tsserverPath: getTsserverExecutable()
2122
});
2223

2324
const tsserverModuleRelativePath = path.join('typescript', 'lib', 'tsserver.js');

0 commit comments

Comments
 (0)