mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-08-16 14:40:23 +03:00
Convert all modern Tree-sitter TODO/hyperlink injections into services
This commit is contained in:
parent
64175c5271
commit
93ab0f7bf0
@ -12,28 +12,19 @@ exports.activate = function () {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
|
||||
atom.grammars.addInjectionPoint(`source.${language}`, {
|
||||
type: 'comment',
|
||||
language: (node) => {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
for (let type of ['string_literal', 'comment']) {
|
||||
atom.grammars.addInjectionPoint(`source.${language}`, {
|
||||
type,
|
||||
language: (node) => {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
for (const language of ['c', 'cpp']) {
|
||||
hyperlink.addInjectionPoint(`source.${language}`, {
|
||||
types: ['comment', 'string_literal']
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
for (const language of ['c', 'cpp']) {
|
||||
todo.addInjectionPoint(`source.${language}`, { types: ['comment'] });
|
||||
}
|
||||
};
|
||||
|
@ -15,5 +15,17 @@
|
||||
"dependencies": {
|
||||
"tree-sitter-c": "0.20.2",
|
||||
"tree-sitter-cpp": "0.20.0"
|
||||
},
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,26 @@
|
||||
exports.activate = () => {
|
||||
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
|
||||
atom.grammars.addInjectionPoint('source.css', {
|
||||
type: 'comment',
|
||||
language(node) {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
hyperlink.addInjectionPoint('source.css', {
|
||||
types: ['comment', 'string_value']
|
||||
});
|
||||
|
||||
for (let type of ['comment', 'string_value']) {
|
||||
atom.grammars.addInjectionPoint('source.css', {
|
||||
type,
|
||||
language(node) {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
}
|
||||
|
||||
// Catch things like
|
||||
//
|
||||
// @import url(https://www.example.com/style.css);
|
||||
//
|
||||
// where the URL is unquoted.
|
||||
atom.grammars.addInjectionPoint('source.css', {
|
||||
type: 'call_expression',
|
||||
hyperlink.addInjectionPoint('source.css', {
|
||||
types: ['call_expression'],
|
||||
language: () => 'hyperlink',
|
||||
content: (node) => {
|
||||
content(node) {
|
||||
let functionName = node.descendantsOfType('function_value')[0]?.text;
|
||||
if (!functionName === 'url') { return null; }
|
||||
|
||||
return node.descendantsOfType('plain_value');
|
||||
},
|
||||
languageScope: null
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
todo.addInjectionPoint('source.css', { types: ['comment'] });
|
||||
};
|
||||
|
@ -14,5 +14,17 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tree-sitter-css": "^0.19.0"
|
||||
},
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,10 @@
|
||||
exports.activate = () => {
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
|
||||
for (let type of ['comment', 'interpreted_string_literal', 'raw_string_literal']) {
|
||||
atom.grammars.addInjectionPoint('source.go', {
|
||||
type,
|
||||
language: (node) => {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
}
|
||||
|
||||
atom.grammars.addInjectionPoint('source.go', {
|
||||
type: 'comment',
|
||||
language(node) {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
hyperlink.addInjectionPoint('source.go', {
|
||||
types: ['comment', 'interpreted_string_literal', 'raw_string_literal']
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
todo.addInjectionPoint('source.go', { types: ['comment'] });
|
||||
};
|
||||
|
@ -14,5 +14,17 @@
|
||||
"repository": "https://github.com/pulsar-edit/pulsar",
|
||||
"dependencies": {
|
||||
"tree-sitter-go": "0.19.1"
|
||||
},
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
exports.activate = function() {
|
||||
exports.activate = function () {
|
||||
atom.grammars.addInjectionPoint('text.html.basic', {
|
||||
type: 'script_element',
|
||||
language() {
|
||||
@ -19,38 +19,6 @@ exports.activate = function() {
|
||||
}
|
||||
});
|
||||
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
|
||||
atom.grammars.addInjectionPoint('text.html.basic', {
|
||||
type: 'comment',
|
||||
language: (node) => {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
atom.grammars.addInjectionPoint('text.html.basic', {
|
||||
type: 'comment',
|
||||
language: (node) => {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
atom.grammars.addInjectionPoint('text.html.basic', {
|
||||
type: 'attribute_value',
|
||||
language: (node) => {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
// TODO: Inject hyperlink grammar into plain text?
|
||||
|
||||
// EMBEDDED
|
||||
|
||||
atom.grammars.addInjectionPoint('text.html.ejs', {
|
||||
@ -95,3 +63,14 @@ exports.activate = function() {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
// TODO: Inject hyperlink grammar into plain text?
|
||||
hyperlink.addInjectionPoint('text.html.basic', {
|
||||
types: ['comment', 'attribute_value']
|
||||
});
|
||||
};
|
||||
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
todo.addInjectionPoint('text.html.basic', { types: ['comment'] });
|
||||
};
|
||||
|
@ -19,5 +19,17 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"dedent": "^0.7.0"
|
||||
},
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
packages/language-html/spec/.eslintrc.js
Normal file
9
packages/language-html/spec/.eslintrc.js
Normal file
@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
env: { jasmine: true },
|
||||
rules: {
|
||||
"node/no-unpublished-require": "off",
|
||||
"node/no-extraneous-require": "off",
|
||||
"no-unused-vars": "off",
|
||||
"no-empty": "off"
|
||||
}
|
||||
};
|
33
packages/language-hyperlink/lib/main.js
Normal file
33
packages/language-hyperlink/lib/main.js
Normal file
@ -0,0 +1,33 @@
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
|
||||
module.exports = {
|
||||
provideHyperlinkInjection() {
|
||||
return {
|
||||
test(node) {
|
||||
return HYPERLINK_PATTERN.test(node.text);
|
||||
},
|
||||
|
||||
addInjectionPoint(scopeName, options) {
|
||||
let types = options.types;
|
||||
if (!Array.isArray(types)) types = [types];
|
||||
|
||||
for (let type of types) {
|
||||
atom.grammars.addInjectionPoint(scopeName, {
|
||||
type,
|
||||
language(node) {
|
||||
if (options.language) {
|
||||
let result = options.language(node);
|
||||
if (result !== undefined) return result;
|
||||
}
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : undefined;
|
||||
},
|
||||
content(node) {
|
||||
return options.content ? options.content(node) : node;
|
||||
},
|
||||
languageScope: null
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
@ -1,11 +1,19 @@
|
||||
{
|
||||
"name": "language-hyperlink",
|
||||
"version": "0.17.1",
|
||||
"main": "lib/main",
|
||||
"description": "Hyperlink colorization in Atom",
|
||||
"engines": {
|
||||
"atom": "*",
|
||||
"node": ">=14"
|
||||
},
|
||||
"repository": "https://github.com/pulsar-edit/pulsar",
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"providedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "provideHyperlinkInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
packages/language-hyperlink/spec/.eslintrc.js
Normal file
13
packages/language-hyperlink/spec/.eslintrc.js
Normal file
@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
env: { jasmine: true },
|
||||
globals: {
|
||||
waitsForPromise: true,
|
||||
advanceClock: true
|
||||
},
|
||||
rules: {
|
||||
"node/no-unpublished-require": "off",
|
||||
"node/no-extraneous-require": "off",
|
||||
"no-unused-vars": "off",
|
||||
"no-empty": "off"
|
||||
}
|
||||
};
|
@ -1,24 +1,10 @@
|
||||
exports.activate = () => {
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
|
||||
atom.grammars.addInjectionPoint('source.java', {
|
||||
type: 'comment',
|
||||
language: (node) => {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
hyperlink.addInjectionPoint('source.java', {
|
||||
types: ['comment', 'string_literal']
|
||||
});
|
||||
|
||||
for (let type of ['string_literal', 'comment']) {
|
||||
atom.grammars.addInjectionPoint('source.java', {
|
||||
type,
|
||||
language: (node) => {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
todo.addInjectionPoint('source.java', { types: ['comment'] });
|
||||
};
|
||||
|
@ -11,5 +11,17 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tree-sitter-java": "0.19.1"
|
||||
},
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,19 +57,6 @@ exports.activate = function () {
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
// TODO: Ideal would be to have one `language-todo` injection for the whole
|
||||
// document responsible for highlighting TODOs in all comments, but
|
||||
// performance needs to be better than it is now for that to be possible.
|
||||
// Injecting into individual line comments results in less time parsing
|
||||
// during buffer modification, but _lots_ of language layers.
|
||||
//
|
||||
// Compromise is to test the content first and then only inject a layer for
|
||||
// `language-todo` when we know it'll be needed. All this also applies for
|
||||
// `language-hyperlink`.
|
||||
//
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
|
||||
atom.grammars.addInjectionPoint('source.js', {
|
||||
type: 'comment',
|
||||
language(comment) {
|
||||
@ -81,28 +68,16 @@ exports.activate = function () {
|
||||
languageScope: null,
|
||||
coverShallowerScopes: true
|
||||
});
|
||||
};
|
||||
|
||||
// Experiment: better to have one layer with lots of nodes, or lots of
|
||||
// layers each managing one node?
|
||||
atom.grammars.addInjectionPoint('source.js', {
|
||||
type: 'comment',
|
||||
language: (node) => {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
hyperlink.addInjectionPoint('source.js', {
|
||||
types: ['comment', 'template_string', 'string_fragment']
|
||||
});
|
||||
};
|
||||
|
||||
for (let type of ['template_string', 'string_fragment', 'comment']) {
|
||||
atom.grammars.addInjectionPoint('source.js', {
|
||||
type,
|
||||
language: (node) => {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
}
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
todo.addInjectionPoint('source.js', { types: ['comment'] });
|
||||
};
|
||||
|
||||
const CSS_REGEX = /\bstyled\b|\bcss\b/i;
|
||||
|
@ -16,5 +16,17 @@
|
||||
"tree-sitter-javascript": "0.19.0",
|
||||
"tree-sitter-jsdoc": "0.19.0",
|
||||
"tree-sitter-regex": "0.19.0"
|
||||
},
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,4 +9,6 @@ injectionRegex: '^(internal-php)$'
|
||||
treeSitter:
|
||||
parserSource: 'github:tree-sitter/tree-sitter-php#594b8bad093abe739c3d2a2cae5abae33c5fb23d'
|
||||
grammar: 'tree-sitter/tree-sitter-php.wasm'
|
||||
# TODO: This shouldn't be necessary. Investigate why a `highlightsQuery` is
|
||||
# still required.
|
||||
highlightsQuery: 'tree-sitter/queries/empty.scm'
|
||||
|
@ -1,3 +1,8 @@
|
||||
function isPhpDoc(node) {
|
||||
let { text } = node;
|
||||
return text.startsWith('/**') && !text.startsWith('/***')
|
||||
}
|
||||
|
||||
exports.activate = function () {
|
||||
|
||||
// Here's how we handle the mixing of PHP and HTML:
|
||||
@ -76,36 +81,6 @@ exports.activate = function () {
|
||||
// TODOs and URLs
|
||||
// ==============
|
||||
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
|
||||
function isPhpDoc(node) {
|
||||
let { text } = node;
|
||||
return text.startsWith('/**') && !text.startsWith('/***')
|
||||
}
|
||||
|
||||
atom.grammars.addInjectionPoint('text.html.php', {
|
||||
type: 'comment',
|
||||
language: (node) => {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
for (let type of ['comment', 'string_value']) {
|
||||
atom.grammars.addInjectionPoint('text.html.php', {
|
||||
type,
|
||||
language(node) {
|
||||
// PHPDoc can parse URLs better than we can.
|
||||
if (isPhpDoc(node)) return undefined;
|
||||
return HYPERLINK_PATTERN.test(node.text) ?
|
||||
'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
}
|
||||
|
||||
// HEREDOCS and NOWDOCS
|
||||
// ====================
|
||||
@ -141,7 +116,7 @@ exports.activate = function () {
|
||||
|
||||
// PHPDoc
|
||||
// ======
|
||||
|
||||
|
||||
atom.grammars.addInjectionPoint('text.html.php', {
|
||||
type: 'comment',
|
||||
language(node) {
|
||||
@ -153,3 +128,16 @@ exports.activate = function () {
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
hyperlink.addInjectionPoint('text.html.php', {
|
||||
types: ['comment', 'string_value'],
|
||||
language(node) {
|
||||
if (isPhpDoc(node)) return null;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
todo.addInjectionPoint('text.html.php', { types: ['comment'] });
|
||||
};
|
||||
|
@ -8,5 +8,17 @@
|
||||
"node": ">=12"
|
||||
},
|
||||
"repository": "https://github.com/pulsar-edit/pulsar",
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
packages/language-php/spec/.eslintrc.js
Normal file
13
packages/language-php/spec/.eslintrc.js
Normal file
@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
env: { jasmine: true },
|
||||
globals: {
|
||||
waitsForPromise: true,
|
||||
advanceClock: true
|
||||
},
|
||||
rules: {
|
||||
"node/no-unpublished-require": "off",
|
||||
"node/no-extraneous-require": "off",
|
||||
"no-unused-vars": "off",
|
||||
"no-empty": "off"
|
||||
}
|
||||
};
|
@ -1,30 +1,6 @@
|
||||
exports.activate = function () {
|
||||
if (!atom.grammars.addInjectionPoint) return;
|
||||
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
|
||||
atom.grammars.addInjectionPoint('source.python', {
|
||||
type: 'comment',
|
||||
language: (node) => {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
for (let type of ['comment', 'string']) {
|
||||
atom.grammars.addInjectionPoint('source.python', {
|
||||
type,
|
||||
language(node) {
|
||||
return HYPERLINK_PATTERN.test(node.text) ?
|
||||
'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: There's no regex literal in Python. The TM-style grammar has a
|
||||
// very obscure option that, when enabled, assumes all raw strings are
|
||||
// regexes and highlights them accordingly. This might be worth doing in the
|
||||
@ -42,3 +18,13 @@ exports.activate = function () {
|
||||
// languageScope: null
|
||||
// });
|
||||
}
|
||||
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
hyperlink.addInjectionPoint('source.python', {
|
||||
types: ['comment', 'string_content']
|
||||
});
|
||||
};
|
||||
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
todo.addInjectionPoint('source.python', { types: ['comment'] });
|
||||
};
|
||||
|
@ -15,5 +15,17 @@
|
||||
"dependencies": {
|
||||
"atom-grammar-test": "^0.6.4",
|
||||
"tree-sitter-python": "0.19.0"
|
||||
},
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,33 +24,14 @@ exports.activate = function () {
|
||||
// coverShallowerScopes: false
|
||||
});
|
||||
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
};
|
||||
|
||||
atom.grammars.addInjectionPoint('source.ruby', {
|
||||
type: 'comment',
|
||||
language: (node) => {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : null;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
atom.grammars.addInjectionPoint('source.ruby', {
|
||||
type: 'comment',
|
||||
language: (node) => {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : null;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
atom.grammars.addInjectionPoint('source.ruby', {
|
||||
type: 'string_content',
|
||||
language: (node) => {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : null;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
hyperlink.addInjectionPoint('source.ruby', {
|
||||
types: ['comment', 'string_content']
|
||||
});
|
||||
};
|
||||
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
todo.addInjectionPoint('source.ruby', { types: ['comment'] });
|
||||
};
|
||||
|
@ -18,5 +18,17 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"dedent": "^0.7.0"
|
||||
},
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,29 +13,21 @@ exports.activate = function () {
|
||||
coverShallowerScopes: true
|
||||
});
|
||||
}
|
||||
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
|
||||
for (let type of ['line_comment', 'block_comment']) {
|
||||
atom.grammars.addInjectionPoint('source.rust', {
|
||||
type,
|
||||
language: (node) => {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
}
|
||||
|
||||
for (let type of ['string_literal', 'raw_string_literal', 'line_comment', 'block_comment']) {
|
||||
atom.grammars.addInjectionPoint('source.rust', {
|
||||
type,
|
||||
language: (node) => {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
hyperlink.addInjectionPoint('source.rust', {
|
||||
types: [
|
||||
'line_comment',
|
||||
'block_comment',
|
||||
'string_literal',
|
||||
'raw_string_literal'
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
todo.addInjectionPoint('source.rust', {
|
||||
types: ['line_comment', 'block_comment']
|
||||
});
|
||||
};
|
||||
|
@ -16,5 +16,17 @@
|
||||
"engines": {
|
||||
"atom": ">=1.0.0 <2.0.0",
|
||||
"node": ">=12"
|
||||
},
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,10 @@
|
||||
exports.activate = () => {
|
||||
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
|
||||
atom.grammars.addInjectionPoint('source.shell', {
|
||||
type: 'comment',
|
||||
language: (node) => {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
hyperlink.addInjectionPoint('source.shell', {
|
||||
types: ['comment']
|
||||
});
|
||||
|
||||
atom.grammars.addInjectionPoint('source.shell', {
|
||||
type: 'comment',
|
||||
language(node) {
|
||||
return HYPERLINK_PATTERN.test(node.text) ?
|
||||
'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
todo.addInjectionPoint('source.shell', { types: ['comment'] });
|
||||
};
|
||||
|
@ -14,5 +14,17 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tree-sitter-bash": "0.19.0"
|
||||
},
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
41
packages/language-todo/lib/main.js
Normal file
41
packages/language-todo/lib/main.js
Normal file
@ -0,0 +1,41 @@
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
|
||||
module.exports = {
|
||||
provideTodoInjection() {
|
||||
return {
|
||||
test(node) {
|
||||
return TODO_PATTERN.test(node.text);
|
||||
},
|
||||
|
||||
// TODO: Ideal would be to have one `language-todo` injection for the
|
||||
// whole document responsible for highlighting TODOs in all comments, but
|
||||
// performance needs to be better than it is now for that to be possible.
|
||||
// Injecting into individual nodes results in less time parsing during
|
||||
// buffer modification, but _lots_ of language layers.
|
||||
//
|
||||
// Compromise is to test the content first and then only inject a layer
|
||||
// for `language-todo` when we know it'll be needed.
|
||||
addInjectionPoint(scopeName, options) {
|
||||
let types = options.types;
|
||||
if (!Array.isArray(types)) types = [types];
|
||||
|
||||
for (let type of types) {
|
||||
atom.grammars.addInjectionPoint(scopeName, {
|
||||
type,
|
||||
language(node) {
|
||||
if (options.language) {
|
||||
let result = options.language(node);
|
||||
if (result !== undefined) return result;
|
||||
}
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content(node) {
|
||||
return options.content ? options.content(node) : node;
|
||||
},
|
||||
languageScope: null
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
@ -1,11 +1,19 @@
|
||||
{
|
||||
"name": "language-todo",
|
||||
"version": "0.29.4",
|
||||
"main": "lib/main",
|
||||
"description": "TODO/FIXME highlighting support in Atom",
|
||||
"engines": {
|
||||
"atom": "*",
|
||||
"node": ">=14"
|
||||
},
|
||||
"repository": "https://github.com/pulsar-edit/pulsar",
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"providedServices": {
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "provideTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,10 @@
|
||||
exports.activate = () => {
|
||||
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
|
||||
atom.grammars.addInjectionPoint('source.toml', {
|
||||
type: 'string',
|
||||
language(node) {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
hyperlink.addInjectionPoint('source.toml', {
|
||||
types: ['comment', 'string']
|
||||
});
|
||||
|
||||
atom.grammars.addInjectionPoint('source.toml', {
|
||||
type: 'comment',
|
||||
language(node) {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
todo.addInjectionPoint('source.toml', { types: ['comment'] });
|
||||
};
|
||||
|
@ -11,5 +11,17 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"tree-sitter-toml": "^0.5.1"
|
||||
},
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,31 +65,24 @@ exports.activate = function () {
|
||||
},
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
atom.grammars.addInjectionPoint(scopeName, {
|
||||
type: 'comment',
|
||||
language: (node) => {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
for (let type of ['template_string', 'string_fragment', 'comment']) {
|
||||
atom.grammars.addInjectionPoint(scopeName, {
|
||||
type,
|
||||
language: (node) => {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
for (const scopeName of ['source.ts', 'source.tsx', 'source.flow']) {
|
||||
hyperlink.addInjectionPoint(scopeName, {
|
||||
types: ['template_string', 'string_fragment', 'comment']
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
for (const scopeName of ['source.ts', 'source.tsx', 'source.flow']) {
|
||||
todo.addInjectionPoint(scopeName, { types: ['comment'] });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const STYLED_REGEX = /\bstyled\b/i;
|
||||
|
||||
function languageStringForTemplateTag(tag) {
|
||||
|
@ -14,5 +14,17 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tree-sitter-typescript": "0.20.1"
|
||||
},
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,10 @@
|
||||
exports.activate = () => {
|
||||
const HYPERLINK_PATTERN = /\bhttps?:/
|
||||
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
|
||||
|
||||
atom.grammars.addInjectionPoint('source.yaml', {
|
||||
type: 'comment',
|
||||
language: (node) => {
|
||||
return HYPERLINK_PATTERN.test(node.text) ? 'hyperlink' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
exports.consumeHyperlinkInjection = (hyperlink) => {
|
||||
hyperlink.addInjectionPoint('source.yaml', {
|
||||
types: ['comment']
|
||||
});
|
||||
|
||||
atom.grammars.addInjectionPoint('source.yaml', {
|
||||
type: 'comment',
|
||||
language: (node) => {
|
||||
return TODO_PATTERN.test(node.text) ? 'todo' : undefined;
|
||||
},
|
||||
content: (node) => node,
|
||||
languageScope: null
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
exports.consumeTodoInjection = (todo) => {
|
||||
todo.addInjectionPoint('source.yaml', { types: ['comment'] });
|
||||
};
|
||||
|
@ -8,5 +8,17 @@
|
||||
"node": ">=12"
|
||||
},
|
||||
"repository": "https://github.com/pulsar-edit/pulsar",
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"consumedServices": {
|
||||
"hyperlink.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeHyperlinkInjection"
|
||||
}
|
||||
},
|
||||
"todo.injection": {
|
||||
"versions": {
|
||||
"0.1.0": "consumeTodoInjection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user