-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sirisak Lueangsaksri
committed
Nov 30, 2016
0 parents
commit dae6423
Showing
10 changed files
with
390 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
out | ||
node_modules | ||
*.vsix | ||
vsc-extension-quickstart.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// A launch configuration that compiles the extension and then opens it inside a new window | ||
{ | ||
"version": "0.1.0", | ||
"configurations": [ | ||
{ | ||
"name": "Launch Extension", | ||
"type": "extensionHost", | ||
"request": "launch", | ||
"runtimeExecutable": "${execPath}", | ||
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ], | ||
"stopOnEntry": false, | ||
"sourceMaps": true, | ||
"outDir": "${workspaceRoot}/out", | ||
"preLaunchTask": "npm" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Place your settings in this file to overwrite default and user settings. | ||
{ | ||
"files.exclude": { | ||
"out": false // set this to true to hide the "out" folder with the compiled JS files | ||
}, | ||
"search.exclude": { | ||
"out": true // set this to false to include "out" folder in search results | ||
}, | ||
"typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Available variables which can be used inside of strings. | ||
// ${workspaceRoot}: the root folder of the team | ||
// ${file}: the current opened file | ||
// ${fileBasename}: the current opened file's basename | ||
// ${fileDirname}: the current opened file's dirname | ||
// ${fileExtname}: the current opened file's extension | ||
// ${cwd}: the current working directory of the spawned process | ||
|
||
// A task runner that calls a custom npm script that compiles the extension. | ||
{ | ||
"version": "0.1.0", | ||
|
||
// we want to run npm | ||
"command": "npm", | ||
|
||
// the command is a shell script | ||
"isShellCommand": true, | ||
|
||
// show the output window only if unrecognized errors occur. | ||
"showOutput": "silent", | ||
|
||
// we run the custom script "compile" as defined in package.json | ||
"args": ["run", "compile", "--loglevel", "silent"], | ||
|
||
// The tsc compiler is started in watching mode | ||
"isWatching": true, | ||
|
||
// use the standard tsc in watch mode problem matcher to find compile problems in the output. | ||
"problemMatcher": "$tsc-watch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.vscode/** | ||
typings/** | ||
out/test/** | ||
test/** | ||
src/** | ||
**/*.map | ||
.gitignore | ||
tsconfig.json | ||
vsc-extension-quickstart.md | ||
*.vsix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Mark Jump | ||
[![Version](http://vsmarketplacebadge.apphb.com/version/spywhere.mark-jump.svg)](https://marketplace.visualstudio.com/items?itemName=spywhere.mark-jump) | ||
[![Installs](http://vsmarketplacebadge.apphb.com/installs/spywhere.mark-jump.svg)](https://marketplace.visualstudio.com/items?itemName=spywhere.mark-jump) | ||
|
||
Jump to the marked section in the code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
{ | ||
"name": "mark-jump", | ||
"displayName": "Mark Jump", | ||
"description": "Jump to the marked section in the code", | ||
"version": "0.0.1", | ||
"publisher": "spywhere", | ||
"bugs": { | ||
"url": "https://github.com/spywhere/vscode-mark-jump/issues" | ||
}, | ||
"homepage": "https://github.com/spywhere/vscode-mark-jump/blob/master/README.md", | ||
"keywords": [ | ||
"marker", | ||
"section", | ||
"jump", | ||
"comment" | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/spywhere/vscode-mark-jump.git" | ||
}, | ||
"engines": { | ||
"vscode": "^1.5.0" | ||
}, | ||
"categories": [ | ||
"Other" | ||
], | ||
"activationEvents": [ | ||
"onCommand:markJump.jumpToSection" | ||
], | ||
"main": "./out/extension", | ||
"contributes": { | ||
"commands": [ | ||
{ | ||
"command": "markJump.jumpToSection", | ||
"title": "Mark Jump: Jump to Section..." | ||
} | ||
], | ||
"configuration": { | ||
"type": "object", | ||
"title": "Mark Jump Configurations", | ||
"properties": { | ||
"markJump.markPatterns": { | ||
"type": "array", | ||
"default": [ | ||
"//\\s*[Mm][Aa][Rr][Kk]\\s*:\\s*(?<name>.+)$", | ||
"#\\s*pragma\\s+(?<name>.+)$" | ||
], | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "A list of regular patterns to match the section." | ||
}, | ||
"markJump.additionalMarkPatterns": { | ||
"type": "array", | ||
"default": [], | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "Additional list of regular pattern to match the section. Use this configuration to avoid replacing default patterns." | ||
}, | ||
"markJump.todoPatterns": { | ||
"type": "array", | ||
"default": [ | ||
"//\\s*[Tt][Oo][Dd][Oo]\\s*(\\((?<writer>[^\\)]+)\\))?\\s*:\\s*(?<description>.+)$", | ||
"//\\s*[Ff][Ii][Xx][Mm][Ee]\\s*(\\((?<writer>[^\\)]+)\\))?\\s*:\\s*(?<description>.+)$" | ||
], | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "A list of regular pattern to match the TODOs." | ||
}, | ||
"markJump.additionalTODOPatterns": { | ||
"type": "array", | ||
"default": [], | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "Additional list of regular pattern to match the TODOs. Use this configuration to avoid replacing default patterns." | ||
}, | ||
"markJump.notePatterns": { | ||
"type": "array", | ||
"default": [ | ||
"//\\s*[Nn][Oo][Tt][Ee]\\s*(\\((?<writer>[^\\)]+)\\))?\\s*:\\s*(?<description>.+)$" | ||
], | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "A list of regular pattern to match the notes." | ||
}, | ||
"markJump.additionalNotePatterns": { | ||
"type": "array", | ||
"default": [], | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "Additional list of regular pattern to match the notes. Use this configuration to avoid replacing default patterns." | ||
} | ||
} | ||
} | ||
}, | ||
"scripts": { | ||
"vscode:prepublish": "tsc -p ./", | ||
"compile": "tsc -watch -p ./", | ||
"postinstall": "node ./node_modules/vscode/bin/install" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^6.0.40", | ||
"@types/xregexp": "^3.0.28", | ||
"typescript": "^2.0.3", | ||
"vscode": "^1.0.0" | ||
}, | ||
"dependencies": { | ||
"xregexp": "^3.1.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
import * as vscode from "vscode"; | ||
import * as XRegExp from "xregexp"; | ||
|
||
export function activate(context: vscode.ExtensionContext) { | ||
console.log("[Mark Jump] Starting..."); | ||
context.subscriptions.push(new MarkJumpController(new MarkJump())); | ||
} | ||
|
||
class MarkJumpController { | ||
private markJump: MarkJump; | ||
private disposable: vscode.Disposable; | ||
|
||
constructor(markJump: MarkJump){ | ||
console.log("[Mark Jump] Activated"); | ||
this.markJump = markJump; | ||
|
||
let subscriptions: vscode.Disposable[] = []; | ||
subscriptions.push(vscode.commands.registerCommand( | ||
"markJump.jumpToSection", this.markJump.jumpToSection | ||
)); | ||
|
||
this.disposable = vscode.Disposable.from(...subscriptions); | ||
} | ||
|
||
dispose(){ | ||
this.disposable.dispose(); | ||
} | ||
} | ||
|
||
interface MarkItem extends vscode.QuickPickItem { | ||
range: vscode.Range; | ||
} | ||
|
||
interface Filter { | ||
test(lineNumber: number, lineText: string): boolean; | ||
getItem(lineNumber: number, lineText: string): MarkItem | undefined; | ||
} | ||
|
||
class MarkJump { | ||
jumpToSection(){ | ||
let filterKeys: string[] = []; | ||
let editor = vscode.window.activeTextEditor; | ||
if(!editor){ | ||
return; | ||
} | ||
let configurations = vscode.workspace.getConfiguration("markJump"); | ||
let filters: Filter[] = []; | ||
|
||
if(filterKeys.length <= 0 || "mark" in filterKeys){ | ||
let patterns = configurations.get<string[]>("markPatterns").concat( | ||
configurations.get<string[]>("additionalMarkPatterns") | ||
); | ||
filters.push(new MarkFilter(patterns)); | ||
} | ||
if(filterKeys.length <= 0 || "todo" in filters){ | ||
let patterns = configurations.get<string[]>("todoPatterns").concat( | ||
configurations.get<string[]>("additionalTODOPatterns") | ||
); | ||
filters.push(new TODOFilter(patterns)); | ||
} | ||
if(filterKeys.length <= 0 || "note" in filters){ | ||
let patterns = configurations.get<string[]>("notePatterns").concat( | ||
configurations.get<string[]>("additionalNotePatterns") | ||
); | ||
filters.push(new NoteFilter(patterns)); | ||
} | ||
if(!filters || filters.length <= 0){ | ||
console.log("[Mark Jump] No filter available"); | ||
return; | ||
} | ||
|
||
let items: MarkItem[] = []; | ||
let lineCount = editor.document.lineCount; | ||
for(let lineNumber = 0; lineNumber < lineCount; lineNumber += 1){ | ||
let lineText = editor.document.lineAt(lineNumber).text; | ||
let item = filters.find( | ||
filter => filter.test(lineNumber, lineText) | ||
).getItem( | ||
lineNumber, lineText | ||
); | ||
if(item){ | ||
items.push(item); | ||
} | ||
} | ||
if(items.length <= 0){ | ||
console.log("[Mark Jump] No item available"); | ||
return; | ||
} | ||
|
||
let lastSelection = editor.selection; | ||
vscode.window.showQuickPick(items, { | ||
onDidSelectItem: (item: MarkItem) => { | ||
editor.revealRange( | ||
item.range, vscode.TextEditorRevealType.InCenter | ||
); | ||
} | ||
}).then(item => { | ||
if(!item){ | ||
editor.revealRange( | ||
lastSelection, vscode.TextEditorRevealType.InCenter | ||
); | ||
return; | ||
} | ||
editor.revealRange( | ||
item.range, vscode.TextEditorRevealType.InCenter | ||
); | ||
}); | ||
} | ||
} | ||
|
||
class MarkFilter implements Filter { | ||
patterns: string[]; | ||
|
||
constructor(patterns: string[] = []){ | ||
this.patterns = patterns; | ||
} | ||
|
||
test(lineNumber: number, lineText: string): boolean { | ||
return this.patterns.some(pattern => { | ||
return XRegExp(pattern).test(lineText); | ||
}); | ||
} | ||
|
||
getItem(lineNumber: number, lineText: string): MarkItem | undefined { | ||
return undefined; | ||
} | ||
} | ||
|
||
class TODOFilter implements Filter { | ||
patterns: string[]; | ||
|
||
constructor(patterns: string[] = []){ | ||
this.patterns = patterns; | ||
} | ||
|
||
test(lineNumber: number, lineText: string): boolean { | ||
return this.patterns.some(pattern => { | ||
return XRegExp(pattern).test(lineText); | ||
}); | ||
} | ||
|
||
getItem(lineNumber: number, lineText: string): MarkItem | undefined { | ||
let item: MarkItem | undefined = undefined; | ||
this.patterns.forEach(pattern => { | ||
let matches = XRegExp(pattern).exec(lineText); | ||
item = { | ||
range: new vscode.Range(lineNumber, 0, lineNumber, 0), | ||
label: "TODO", | ||
description: matches["description"] || "Description", | ||
detail: matches["writer"] || "Detail" | ||
}; | ||
}); | ||
return item; | ||
} | ||
} | ||
|
||
class NoteFilter implements Filter { | ||
patterns: string[]; | ||
|
||
constructor(patterns: string[] = []){ | ||
this.patterns = patterns; | ||
} | ||
|
||
test(lineNumber: number, lineText: string): boolean { | ||
return this.patterns.some(pattern => { | ||
return XRegExp(pattern).test(lineText); | ||
}); | ||
} | ||
|
||
getItem(lineNumber: number, lineText: string): MarkItem | undefined { | ||
return undefined; | ||
} | ||
} |
Oops, something went wrong.