fix(code/frontend): improve regexp that matches the container of a symbol (#37856) (#38089)

This commit is contained in:
WangQianliang 2019-06-06 22:24:18 +08:00 committed by GitHub
parent 77dd34b1b2
commit d592f54910
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View file

@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { matchContainerName } from '../../utils/symbol_utils';
describe('matchSymbolName', () => {
it('should match symbol that has type annotation', () => {
expect(matchContainerName('Session', 'Session<key, value>')).toBe(true);
});
it('should not match symbol that has same start but not end with type annotation', () => {
expect(matchContainerName('Session', 'SessionTail')).toBe(false);
});
});

View file

@ -13,6 +13,7 @@ import { loadStructure, loadStructureFailed, loadStructureSuccess } from '../act
import { ServerNotInitialized } from '../../common/lsp_error_codes';
import { languageServerInitializing } from '../actions/language_server';
import { SymbolWithMembers } from '../reducers/symbol';
import { matchContainerName } from '../utils/symbol_utils';
const STRUCTURE_TREE_POLLING_INTERVAL_SEC = 3;
@ -40,9 +41,8 @@ const generateStructureTree: (symbols: SymbolInformation[]) => any = symbols =>
if (containerName === undefined) {
return undefined;
}
const regex = new RegExp(`^${containerName}[<(]?.*[>)]?$`);
const result = tree.find((s: SymbolInformation) => {
return regex.test(s.name);
return matchContainerName(containerName, s.name);
});
if (result) {
return result;

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
export const matchContainerName = (containerName: string, symbolName: string) =>
new RegExp(`^${containerName}[[<(].*[>)]]?$`).test(symbolName);