Skip to content

Commit

Permalink
[Code]Add ctags langserver as a dependency and launch it (#39763)
Browse files Browse the repository at this point in the history
* Add ctags langserver as a dependency and launch it

* Remove extra files in node-ctags when release

* [build] rework platform-specific clean for ctag package

* rename local excludedPath var

* use array.includes

* exclude ctags langserver vendor
  • Loading branch information
Pengcheng Xu authored Jul 3, 2019
1 parent 2fd04d4 commit 1e1153e
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/dev/build/build_distributables.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
CleanTypescriptTask,
CleanNodeBuildsTask,
CleanTask,
CleanCtagBuildTask,
CopySourceTask,
CreateArchivesSourcesTask,
CreateArchivesTask,
Expand Down Expand Up @@ -134,6 +135,7 @@ export async function buildDistributables(options) {
await run(CleanExtraBinScriptsTask);
await run(CleanExtraBrowsersTask);
await run(CleanNodeBuildsTask);
await run(CleanCtagBuildTask);

await run(PathLengthTask);

Expand Down
33 changes: 32 additions & 1 deletion src/dev/build/lib/scan_delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ afterAll(async () => {
await del(TMP);
});

it('requires an absolute directory', async () => {
it('requires absolute paths', async () => {
await expect(
scanDelete({
directory: relative(process.cwd(), TMP),
Expand All @@ -51,6 +51,16 @@ it('requires an absolute directory', async () => {
).rejects.toMatchInlineSnapshot(
`[TypeError: Please use absolute paths to keep things explicit. You probably want to use \`build.resolvePath()\` or \`config.resolveFromRepo()\`.]`
);

await expect(
scanDelete({
directory: TMP,
regularExpressions: [],
excludePaths: ['foo'],
})
).rejects.toMatchInlineSnapshot(
`[TypeError: Please use absolute paths to keep things explicit. You probably want to use \`build.resolvePath()\` or \`config.resolveFromRepo()\`.]`
);
});

it('deletes files/folders matching regular expression', async () => {
Expand All @@ -62,3 +72,24 @@ it('deletes files/folders matching regular expression', async () => {
expect(readdirSync(resolve(TMP, 'a'))).toEqual(['b']);
expect(readdirSync(resolve(TMP, 'a/b'))).toEqual([]);
});

it('exludes directories mentioned in excludePaths', async () => {
await scanDelete({
directory: TMP,
regularExpressions: [/^.*[\/\\](bar|c)([\/\\]|$)/],
excludePaths: [resolve(TMP, 'foo')],
});
expect(readdirSync(resolve(TMP, 'foo'))).toEqual(['bar']);
expect(readdirSync(resolve(TMP, 'a'))).toEqual(['b']);
expect(readdirSync(resolve(TMP, 'a/b'))).toEqual([]);
});

it('exludes files mentioned in excludePaths', async () => {
await scanDelete({
directory: TMP,
regularExpressions: [/box/],
excludePaths: [resolve(TMP, 'foo/bar/box')],
});

expect(readdirSync(resolve(TMP, 'foo/bar'))).toEqual(['baz', 'box']);
});
8 changes: 7 additions & 1 deletion src/dev/build/lib/scan_delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface Options {
directory: string;
regularExpressions: RegExp[];
concurrency?: 20;
excludePaths?: string[];
}

/**
Expand All @@ -45,9 +46,10 @@ interface Options {
* @param options.concurrency optional concurrency to run deletes, defaults to 20
*/
export async function scanDelete(options: Options) {
const { directory, regularExpressions, concurrency = 20 } = options;
const { directory, regularExpressions, concurrency = 20, excludePaths } = options;

assertAbsolute(directory);
(excludePaths || []).forEach(excluded => assertAbsolute(excluded));

// get an observable of absolute paths within a directory
const getChildPath$ = (path: string) =>
Expand All @@ -60,6 +62,10 @@ export async function scanDelete(options: Options) {
// and recursively iterating through all children, unless a child matches
// one of the supplied regular expressions
const getPathsToDelete$ = (path: string): Rx.Observable<string> => {
if (excludePaths && excludePaths.includes(path)) {
return Rx.EMPTY;
}

if (regularExpressions.some(re => re.test(path))) {
return Rx.of(path);
}
Expand Down
38 changes: 37 additions & 1 deletion src/dev/build/tasks/clean_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import minimatch from 'minimatch';

import { deleteAll, deleteEmptyFolders, scanDelete } from '../lib';
import { resolve } from 'path';

const RELATIVE_CTAGS_BUILD_DIR = 'node_modules/@elastic/node-ctags/ctags/build';

export const CleanTask = {
global: true,
Expand Down Expand Up @@ -168,7 +171,10 @@ export const CleanExtraFilesFromModulesTask = {

log.info('Deleted %d files', await scanDelete({
directory: build.resolvePath('node_modules'),
regularExpressions
regularExpressions,
excludePaths: [
build.resolvePath('node_modules/@elastic/ctags-langserver/vendor')
]
}));

if (!build.isOss()) {
Expand Down Expand Up @@ -255,3 +261,33 @@ export const CleanEmptyFoldersTask = {
);
},
};

export const CleanCtagBuildTask = {
description: 'Cleaning extra platform-specific files from @elastic/node-ctag build dir',

async run(config, log, build) {
const getPlatformId = (platform) => {
if (platform.isWindows()) {
return 'win32';
} else if (platform.isLinux()) {
return 'linux';
} else if (platform.isMac()) {
return 'darwin';
}
};

await Promise.all(
config.getTargetPlatforms().map(async platform => {
if (build.isOss()) {
return;
}

const ctagsBuildDir = build.resolvePathForPlatform(platform, RELATIVE_CTAGS_BUILD_DIR);
await deleteAll([
resolve(ctagsBuildDir, '*'),
`!${resolve(ctagsBuildDir, `ctags-node-v${process.versions.modules}-${getPlatformId(platform)}-x64`)}`
], log);
})
);
}
};
3 changes: 3 additions & 0 deletions src/dev/license_checker/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const LICENSE_WHITELIST = [
'Unlicense',
'WTFPL OR ISC',
'WTFPL',
'Nuclide software',
];

// The following list only applies to licenses that
Expand Down Expand Up @@ -106,4 +107,6 @@ export const LICENSE_OVERRIDES = {

// TODO remove this once we upgrade past or equal to v1.0.2
'[email protected]': ['MIT'],

'@elastic/[email protected]': ['Nuclide software'],
};
13 changes: 11 additions & 2 deletions x-pack/legacy/plugins/code/server/lsp/ctags_launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ export class CtagsLauncher extends AbstractLauncher {
}

async spawnProcess(installationPath: string, port: number, log: Logger) {
// TODO(pcxu): add spawn command here for ctags langserver
return spawn('');
const p = spawn(process.execPath, [installationPath, `--socket=${port.toString()}`], {
detached: false,
stdio: 'pipe',
});
p.stdout.on('data', data => {
log.stdout(data.toString());
});
p.stderr.on('data', data => {
log.stderr(data.toString());
});
return p;
}
}
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/code/server/lsp/language_servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export const CTAGS: LanguageServerDefinition = {
'yacc',
],
launcher: CtagsLauncher,
installationType: InstallationType.Plugin,
installationPluginName: 'ctagsLanguageServer',
installationType: InstallationType.Embed,
embedPath: require.resolve('@elastic/ctags-langserver/lib/cli.js'),
};
export const LanguageServers: LanguageServerDefinition[] = [TYPESCRIPT, JAVA];
export const LanguageServersDeveloping: LanguageServerDefinition[] = [GO, CTAGS];
Expand Down
1 change: 1 addition & 0 deletions x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
"@babel/polyfill": "7.4.4",
"@babel/register": "7.4.4",
"@babel/runtime": "7.4.5",
"@elastic/ctags-langserver": "^0.0.5",
"@elastic/datemath": "5.0.2",
"@elastic/eui": "12.2.0",
"@elastic/javascript-typescript-langserver": "^0.2.0",
Expand Down
33 changes: 32 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,19 @@
ts-debounce "^1.0.0"
uuid "^3.3.2"

"@elastic/ctags-langserver@^0.0.5":
version "0.0.5"
resolved "https://registry.yarnpkg.com/@elastic/ctags-langserver/-/ctags-langserver-0.0.5.tgz#2ee09024a5106c548a1ddb52992352c577e38a66"
integrity sha512-XEpB60SW4/jo+r7r06Uro5n7Mv1iqWwirqBWtHwhaIV17QKsjU4uRn3RZ7gwm9uHu5kri0RSnu3hfRuSskCyEw==
dependencies:
"@elastic/lsp-extension" "^0.1.1"
"@elastic/node-ctags" "1.0.2"
commander "^2.11.0"
find-root "^1.1.0"
grep1 "^0.0.5"
line-column "^1.0.2"
vscode-languageserver "^5.2.1"

"@elastic/elasticsearch@^7.0.0-rc.2":
version "7.0.0-rc.2"
resolved "https://registry.yarnpkg.com/@elastic/elasticsearch/-/elasticsearch-7.0.0-rc.2.tgz#2fb07978d647a257af3976b170e3f61704ba0a18"
Expand Down Expand Up @@ -1701,7 +1714,7 @@
typescript "~3.3.3333"
yarn "^1.12.3"

"@elastic/lsp-extension@^0.1.2":
"@elastic/lsp-extension@^0.1.1", "@elastic/lsp-extension@^0.1.2":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@elastic/lsp-extension/-/lsp-extension-0.1.2.tgz#7356d951d272e833d02a81e13a0ef710f9474195"
integrity sha512-yDj5Ht5KCHDwBlgrlusmLtV/Yxa5z2f3vMSYbNFotoRMup8345/ZwlFp/zmyl04iFOVpT8ouB34+Ttpzbpd3vA==
Expand Down Expand Up @@ -1735,6 +1748,11 @@
resolved "https://registry.yarnpkg.com/@elastic/node-crypto/-/node-crypto-1.0.0.tgz#4d325df333fe1319556bb4d54214098ada1171d4"
integrity sha512-bbjbEyILPRTRt0xnda18OttLtlkJBPuXx3CjISUSn9jhWqHoFMzfOaZ73D5jxZE2SaFZUrJYfPpqXP6qqPufAQ==

"@elastic/[email protected]":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@elastic/node-ctags/-/node-ctags-1.0.2.tgz#447d7694a5598f9413fe2b6f356d56f64f612dfd"
integrity sha512-EHhJ0NPlCvYy+gbzBMU4/Z/55hftfdwlAG8JwOy7g0ITmH6rFPanEnzg1WL3/L+pp8OlYHyvDLwmyg0+06y8LQ==

"@elastic/[email protected]":
version "0.25.0-alpha.22"
resolved "https://registry.yarnpkg.com/@elastic/nodegit/-/nodegit-0.25.0-alpha.22.tgz#71c112c7f5284eabef91fa3e1acf689ba9cdc875"
Expand Down Expand Up @@ -13912,6 +13930,11 @@ graphviz@^0.0.8:
dependencies:
temp "~0.4.0"

grep1@^0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/grep1/-/grep1-0.0.5.tgz#8e185b8f063973e7c465c107938c86f52c34fb74"
integrity sha1-jhhbjwY5c+fEZcEHk4yG9Sw0+3Q=

grid-index@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/grid-index/-/grid-index-1.1.0.tgz#97f8221edec1026c8377b86446a7c71e79522ea7"
Expand Down Expand Up @@ -17606,6 +17629,14 @@ liftoff@^2.1.0:
rechoir "^0.6.2"
resolve "^1.1.7"

line-column@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/line-column/-/line-column-1.0.2.tgz#d25af2936b6f4849172b312e4792d1d987bc34a2"
integrity sha1-0lryk2tvSEkXKzEuR5LR2Ye8NKI=
dependencies:
isarray "^1.0.0"
isobject "^2.0.0"

linebreak@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/linebreak/-/linebreak-0.3.0.tgz#0526480a62c05bd679f3e9d99830e09c6a7d0ed6"
Expand Down

0 comments on commit 1e1153e

Please sign in to comment.