Merge from vscode a4177f50c475fc0fa278a78235e3bee9ffdec781 (#8649)

* Merge from vscode a4177f50c475fc0fa278a78235e3bee9ffdec781

* distro

* fix tests
This commit is contained in:
Anthony Dresser
2019-12-11 22:42:23 -08:00
committed by GitHub
parent 82974a2135
commit 4ba6a979ba
280 changed files with 10898 additions and 14231 deletions

View File

@@ -392,7 +392,7 @@ export class Model {
if (hint instanceof Uri) {
let resourcePath: string;
if (hint.scheme === 'git') {
if (hint.scheme === 'git' || hint.scheme === 'gitfs') {
resourcePath = fromGitUri(hint).path;
} else {
resourcePath = hint.fsPath;

View File

@@ -4,7 +4,7 @@
"If you want to provide a fix or improvement, please create a pull request against the original repository.",
"Once accepted there, we are happy to receive an update request."
],
"version": "https://github.com/microsoft/vscode-markdown-tm-grammar/commit/e3091a421bdcad527018c897652ded47585cbd12",
"version": "https://github.com/microsoft/vscode-markdown-tm-grammar/commit/8fbbc11a6bb917f287bbe21d0573454020599547",
"name": "Markdown",
"scopeName": "text.html.markdown",
"patterns": [
@@ -2623,4 +2623,4 @@
"name": "markup.inline.raw.string.markdown"
}
}
}
}

View File

@@ -346,7 +346,7 @@
"mocha-junit-reporter": "^1.17.0",
"mocha-multi-reporters": "^1.1.7",
"ts-loader": "^6.2.1",
"typescript": "^3.7.2",
"typescript": "^3.7.3",
"vscode": "^1.1.10",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.0"

View File

@@ -4528,10 +4528,10 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
typescript@^3.7.2:
version "3.7.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb"
integrity sha512-ml7V7JfiN2Xwvcer+XAf2csGO1bPBdRbFCkYBczNZggrBZ9c7G3riSUeJmqEU5uOtXNPMhE3n+R4FA/3YOAWOQ==
typescript@^3.7.3:
version "3.7.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.3.tgz#b36840668a16458a7025b9eabfad11b66ab85c69"
integrity sha512-Mcr/Qk7hXqFBXMN7p7Lusj1ktCBydylfQM/FZCk5glCNQJrCUKPkMHdo9R0MTFWsC/4kPFvDS0fDPvukfCkFsw==
uc.micro@^1.0.1:
version "1.0.3"

View File

@@ -16,6 +16,7 @@
"*"
],
"scripts": {
"generate-grammar": "node ./syntaxes/generateTMLanguage.js",
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:search-result ./tsconfig.json"
},
"contributes": {

View File

@@ -12,9 +12,27 @@ const SEARCH_RESULT_SELECTOR = { language: 'search-result' };
const DIRECTIVES = ['# Query:', '# Flags:', '# Including:', '# Excluding:', '# ContextLines:'];
const FLAGS = ['RegExp', 'CaseSensitive', 'IgnoreExcludeSettings', 'WordMatch'];
let cachedLastParse: { version: number, parse: ParsedSearchResults } | undefined;
let cachedLastParse: { version: number, parse: ParsedSearchResults, uri: vscode.Uri } | undefined;
let documentChangeListener: vscode.Disposable | undefined;
export function activate(context: vscode.ExtensionContext) {
const contextLineDecorations = vscode.window.createTextEditorDecorationType({ opacity: '0.7' });
const matchLineDecorations = vscode.window.createTextEditorDecorationType({ fontWeight: 'bold' });
const decorate = (editor: vscode.TextEditor) => {
const parsed = parseSearchResults(editor.document).filter(isResultLine);
const contextRanges = parsed.filter(line => line.isContext).map(line => line.prefixRange);
const matchRanges = parsed.filter(line => !line.isContext).map(line => line.prefixRange);
editor.setDecorations(contextLineDecorations, contextRanges);
editor.setDecorations(matchLineDecorations, matchRanges);
};
if (vscode.window.activeTextEditor && vscode.window.activeTextEditor.document.languageId === 'search-result') {
decorate(vscode.window.activeTextEditor);
}
context.subscriptions.push(
vscode.commands.registerCommand('searchResult.rerunSearch', () => vscode.commands.executeCommand('search.action.rerunEditorSearch')),
vscode.commands.registerCommand('searchResult.rerunSearchWithContext', () => vscode.commands.executeCommand('search.action.rerunEditorSearchWithContext')),
@@ -84,15 +102,24 @@ export function activate(context: vscode.ExtensionContext) {
}
}),
vscode.window.onDidChangeActiveTextEditor(e => {
if (e?.document.languageId === 'search-result') {
vscode.window.onDidChangeActiveTextEditor(editor => {
if (editor?.document.languageId === 'search-result') {
// Clear the parse whenever we open a new editor.
// Conservative because things like the URI might remain constant even if the contents change, and re-parsing even large files is relatively fast.
cachedLastParse = undefined;
documentChangeListener?.dispose();
documentChangeListener = vscode.workspace.onDidChangeTextDocument(doc => {
if (doc.document.uri === editor.document.uri) {
decorate(editor);
}
});
decorate(editor);
}
}),
{ dispose() { cachedLastParse = undefined; } }
{ dispose() { cachedLastParse = undefined; documentChangeListener?.dispose(); } }
);
}
@@ -129,14 +156,15 @@ function relativePathToUri(path: string, resultsUri: vscode.Uri): vscode.Uri | u
}
type ParsedSearchFileLine = { type: 'file', location: vscode.LocationLink, allLocations: vscode.LocationLink[], path: string };
type ParsedSearchResultLine = { type: 'result', location: vscode.LocationLink };
type ParsedSearchResultLine = { type: 'result', location: vscode.LocationLink, isContext: boolean, prefixRange: vscode.Range };
type ParsedSearchResults = Array<ParsedSearchFileLine | ParsedSearchResultLine>;
const isFileLine = (line: ParsedSearchResultLine | ParsedSearchFileLine): line is ParsedSearchFileLine => line.type === 'file';
const isResultLine = (line: ParsedSearchResultLine | ParsedSearchFileLine): line is ParsedSearchResultLine => line.type === 'result';
function parseSearchResults(document: vscode.TextDocument, token: vscode.CancellationToken): ParsedSearchResults {
function parseSearchResults(document: vscode.TextDocument, token?: vscode.CancellationToken): ParsedSearchResults {
if (cachedLastParse && cachedLastParse.version === document.version) {
if (cachedLastParse && cachedLastParse.uri === document.uri && cachedLastParse.version === document.version) {
return cachedLastParse.parse;
}
@@ -147,7 +175,8 @@ function parseSearchResults(document: vscode.TextDocument, token: vscode.Cancell
let currentTargetLocations: vscode.LocationLink[] | undefined = undefined;
for (let i = 0; i < lines.length; i++) {
if (token.isCancellationRequested) { return []; }
// TODO: This is probably always false, given we're pegging the thread...
if (token?.isCancellationRequested) { return []; }
const line = lines[i];
const fileLine = FILE_LINE_REGEX.exec(line);
@@ -186,13 +215,14 @@ function parseSearchResults(document: vscode.TextDocument, token: vscode.Cancell
currentTargetLocations?.push(location);
links[i] = { type: 'result', location };
links[i] = { type: 'result', location, isContext: seperator === ' ', prefixRange: new vscode.Range(i, 0, i, metadataOffset) };
}
}
cachedLastParse = {
version: document.version,
parse: links
parse: links,
uri: document.uri
};
return links;

View File

@@ -0,0 +1,243 @@
// @ts-check
const mappings = [
['bat', 'source.batchfile'],
['c', 'source.c'],
['cc', 'source.cpp'],
['clj', 'source.clojure'],
['coffee', 'source.coffee'],
['cpp', 'source.cpp'],
['cs', 'source.cs'],
['cshtml', 'text.html.cshtml'],
['css', 'source.css'],
['dart', 'source.dart'],
['diff', 'source.diff'],
['dockerfile', 'source.dockerfile', '(?:dockerfile|Dockerfile)'],
['fs', 'source.fsharp'],
['go', 'source.go'],
['groovy', 'source.groovy'],
['h', 'source.objc'],
['handlebars', 'text.html.handlebars'],
['hbs', 'text.html.handlebars'],
['hlsl', 'source.hlsl'],
['hpp', 'source.objcpp'],
['html', 'text.html.basic'],
['ini', 'source.ini'],
['java', 'source.java'],
['js', 'source.js'],
['json', 'source.json.comments'],
['jsx', 'source.js.jsx'],
['less', 'source.css.less'],
['log', 'text.log'],
['lua', 'source.lua'],
['m', 'source.objc'],
['makefile', 'source.makefile', '(?:makefile|Makefile)(?:\\..*)?'],
['md', 'text.html.markdown'],
['mm', 'source.objcpp'],
['p6', 'source.perl.6'],
['perl', 'source.perl'],
['php', 'source.php'],
['pl', 'source.perl'],
['ps1', 'source.powershell'],
['pug', 'text.pug'],
['py', 'source.python'],
['r', 'source.r'],
['rb', 'source.ruby'],
['rs', 'source.rust'],
['scala', 'source.scala'],
['scss', 'source.css.scss'],
['sh', 'source.shell'],
['sql', 'source.sql'],
['swift', 'source.swift'],
['ts', 'source.ts'],
['tsx', 'source.tsx'],
['vb', 'source.asp.vb.net'],
['xml', 'text.xml'],
['yaml', 'source.yaml'],
];
const scopes = {
root: 'text.searchResult',
header: {
meta: 'meta.header.search keyword.operator.word.search',
key: 'entity.other.attribute-name',
value: 'entity.other.attribute-value string.unquoted',
flags: {
keyword: 'keyword.other',
},
contextLines: {
number: 'constant.numeric.integer',
invalid: 'invalid.illegal',
},
query: {
escape: 'constant.character.escape',
invalid: 'invalid.illegal',
}
},
resultBlock: {
meta: 'meta.resultBlock.search',
path: {
meta: 'string meta.path.search',
dirname: 'meta.path.dirname.search',
basename: 'meta.path.basename.search',
colon: 'punctuation.separator',
},
result: {
meta: 'meta.resultLine.search',
metaSingleLine: 'meta.resultLine.singleLine.search',
metaMultiLine: 'meta.resultLine.multiLine.search',
prefix: {
meta: 'constant.numeric.integer meta.resultLinePrefix.search',
metaContext: 'meta.resultLinePrefix.contextLinePrefix.search',
metaMatch: 'meta.resultLinePrefix.matchLinePrefix.search',
lineNumber: 'meta.resultLinePrefix.lineNumber.search',
colon: 'punctuation.separator',
}
}
}
};
const repository = {};
mappings.forEach(([ext, scope, regexp]) =>
repository[ext] = {
name: scopes.resultBlock.meta,
begin: `^(?!\\s)(.*?)([^\\\\\\/\\n]*${regexp || `\\.${ext}`})(:)$`,
end: "^(?!\\s)",
beginCaptures: {
"0": { name: scopes.resultBlock.path.meta },
"1": { name: scopes.resultBlock.path.dirname },
"2": { name: scopes.resultBlock.path.basename },
"3": { name: scopes.resultBlock.path.colon },
},
patterns: [
{
name: [scopes.resultBlock.result.meta, scopes.resultBlock.result.metaMultiLine].join(' '),
begin: "^ ((\\d+) )",
while: "^ ((\\d+)(:))|((\\d+) )",
beginCaptures: {
"0": { name: scopes.resultBlock.result.prefix.meta },
"1": { name: scopes.resultBlock.result.prefix.metaContext },
"2": { name: scopes.resultBlock.result.prefix.lineNumber },
},
whileCaptures: {
"0": { name: scopes.resultBlock.result.prefix.meta },
"1": { name: scopes.resultBlock.result.prefix.metaMatch },
"2": { name: scopes.resultBlock.result.prefix.lineNumber },
"3": { name: scopes.resultBlock.result.prefix.colon },
"4": { name: scopes.resultBlock.result.prefix.metaContext },
"5": { name: scopes.resultBlock.result.prefix.lineNumber },
},
patterns: [{ include: scope }]
},
{
begin: "^ ((\\d+)(:))",
while: "(?=not)possible",
name: [scopes.resultBlock.result.meta, scopes.resultBlock.result.metaSingleLine].join(' '),
beginCaptures: {
"0": { name: scopes.resultBlock.result.prefix.meta },
"1": { name: scopes.resultBlock.result.prefix.metaMatch },
"2": { name: scopes.resultBlock.result.prefix.lineNumber },
"3": { name: scopes.resultBlock.result.prefix.colon },
},
patterns: [{ include: scope }]
}
]
});
const header = [
{
begin: "^(# Query): ",
end: "\n",
name: scopes.header.meta,
beginCaptures: { "1": { name: scopes.header.key }, },
patterns: [
{
match: '(\\\\n)|(\\\\\\\\)',
name: [scopes.header.value, scopes.header.query.escape].join(' ')
},
{
match: '\\\\.|\\\\$',
name: [scopes.header.value, scopes.header.query.invalid].join(' ')
},
{
match: '[^\\\\\\\n]+',
name: [scopes.header.value].join(' ')
},
]
},
{
begin: "^(# Flags): ",
end: "\n",
name: scopes.header.meta,
beginCaptures: { "1": { name: scopes.header.key }, },
patterns: [
{
match: '(RegExp|CaseSensitive|IgnoreExcludeSettings|WordMatch)',
name: [scopes.header.value, 'keyword.other'].join(' ')
},
{ match: '.' },
]
},
{
begin: "^(# ContextLines): ",
end: "\n",
name: scopes.header.meta,
beginCaptures: { "1": { name: scopes.header.key }, },
patterns: [
{
match: '\\d',
name: [scopes.header.value, scopes.header.contextLines.number].join(' ')
},
{ match: '.', name: scopes.header.contextLines.invalid },
]
},
{
match: "^(# (?:Including|Excluding)): (.*)$",
name: scopes.header.meta,
captures: {
"1": { name: scopes.header.key },
"2": { name: scopes.header.value }
}
},
];
const plainText = [
{
match: "^(?!\\s)(.*?)([^\\\\\\/\\n]*)(:)$",
name: [scopes.resultBlock.meta, scopes.resultBlock.path.meta].join(' '),
captures: {
"1": { name: scopes.resultBlock.path.dirname },
"2": { name: scopes.resultBlock.path.basename },
"3": { name: scopes.resultBlock.path.colon }
}
},
{
match: "^ ((\\d+)(:))|((\\d+)( ))(.*)",
name: [scopes.resultBlock.meta, scopes.resultBlock.result.meta].join(' '),
captures: {
"1": { name: [scopes.resultBlock.result.prefix.meta, scopes.resultBlock.result.prefix.metaMatch].join(' ') },
"2": { name: scopes.resultBlock.result.prefix.lineNumber },
"3": { name: scopes.resultBlock.result.prefix.colon },
"4": { name: [scopes.resultBlock.result.prefix.meta, scopes.resultBlock.result.prefix.metaContext].join(' ') },
"5": { name: scopes.resultBlock.result.prefix.lineNumber },
}
}
];
const tmLanguage = {
"information_for_contributors": "This file is generated from ./generateTMLanguage.js.",
name: "Search Results",
scopeName: scopes.root,
patterns: [
...header,
...mappings.map(([ext]) => ({ include: `#${ext}` })),
...plainText
],
repository
};
require('fs').writeFileSync(
require('path').join(__dirname, './searchResult.tmLanguage.json'),
JSON.stringify(tmLanguage, null, 2));

File diff suppressed because it is too large Load Diff

View File

@@ -114,6 +114,13 @@
"settings": {
"foreground": "#CE9178"
}
},
{
"name": "HC Search Editor context line override",
"scope": "meta.resultLinePrefix.contextLinePrefix.search",
"settings": {
"foreground": "#CBEDCB",
}
}
]
}