-
Notifications
You must be signed in to change notification settings - Fork 43
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
0 parents
commit f77f901
Showing
20 changed files
with
1,243 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,6 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
insert_final_newline = true |
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,3 @@ | ||
out | ||
node_modules | ||
*.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,28 @@ | ||
// 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/src", | ||
"preLaunchTask": "npm" | ||
}, | ||
{ | ||
"name": "Launch Tests", | ||
"type": "extensionHost", | ||
"request": "launch", | ||
"runtimeExecutable": "${execPath}", | ||
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ], | ||
"stopOnEntry": false, | ||
"sourceMaps": true, | ||
"outDir": "${workspaceRoot}/out/test", | ||
"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,9 @@ | ||
.vscode/** | ||
typings/** | ||
out/test/** | ||
test/** | ||
src/** | ||
**/*.map | ||
.gitignore | ||
tsconfig.json | ||
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 Christophe Feijoo | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
# 42 header for VSCode |
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 little install script to | ||
# remember howto install extension | ||
npm install | ||
vsce package | ||
code --uninstall-extension kube.42header | ||
code --install-extension 42header*.vsix | ||
rm 42header*.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,55 @@ | ||
{ | ||
"name": "42header", | ||
"displayName": "42 Header", | ||
"description": "42 header for VSCode : www.42.fr", | ||
"version": "0.1.3", | ||
"publisher": "kube", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/kube/vscode-42header" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/kube/vscode-42header/issues" | ||
}, | ||
"homepage": "https://github.com/kube/vscode-42header", | ||
"license": "MIT", | ||
"engines": { | ||
"vscode": "^1.4.0" | ||
}, | ||
"categories": [ | ||
"Other" | ||
], | ||
"activationEvents": [ | ||
"*" | ||
], | ||
"main": "./out/src/extension", | ||
"contributes": { | ||
"commands": [ | ||
{ | ||
"command": "42header.insertHeader", | ||
"title": "Insert 42 header", | ||
"when": "editorTextFocus" | ||
} | ||
], | ||
"keybindings": [ | ||
{ | ||
"command": "42header.insertHeader", | ||
"key": "ctrl+alt+h", | ||
"mac": "cmd+alt+h", | ||
"when": "editorTextFocus" | ||
} | ||
] | ||
}, | ||
"scripts": { | ||
"vscode:prepublish": "node ./node_modules/vscode/bin/compile", | ||
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./", | ||
"postinstall": "node ./node_modules/vscode/bin/install" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^2.0.0", | ||
"vscode": "^0.11.0" | ||
}, | ||
"dependencies": { | ||
"moment": "^2.15.0" | ||
} | ||
} |
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,56 @@ | ||
|
||
/*#######. | ||
########",#: | ||
#########',##". | ||
##'##'## .##',##. | ||
## ## ## # ##",#. | ||
## ## ## ## ##' | ||
## ## ## :## | ||
## ## ##*/ | ||
|
||
const hashes = ['# ', ' #'] | ||
const slashes = ['/* ', ' */'] | ||
const semicolons = [';; ', ' ;;'] | ||
const parens = ['(* ', ' *)'] | ||
const dashes = ['-- ', ' --'] | ||
const percents = ['%% ', ' %%'] | ||
|
||
export const languageDemiliters: { [index: string]: string[] | null } = { | ||
'c': slashes, | ||
'coffeescript': hashes, | ||
'cpp': slashes, | ||
'css': slashes, | ||
'dockerfile': hashes, | ||
'fsharp': parens, | ||
'go': slashes, | ||
'groovy': slashes, | ||
'haskell': dashes, | ||
'ini': semicolons, | ||
'jade': slashes, | ||
'java': slashes, | ||
'javascript': slashes, | ||
'javascriptreact': slashes, | ||
'latex': percents, | ||
'less': slashes, | ||
'lua': semicolons, | ||
'makefile': hashes, | ||
'objective-c': slashes, | ||
'ocaml': parens, | ||
'perl': hashes, | ||
'perl6': hashes, | ||
'php': slashes, | ||
'plaintext': hashes, | ||
'powershell': hashes, | ||
'python': hashes, | ||
'r': hashes, | ||
'ruby': hashes, | ||
'rust': slashes, | ||
'scss': slashes, | ||
'shellscript': hashes, | ||
'sql': hashes, | ||
'swift': slashes, | ||
'typescript': slashes, | ||
'typescriptreact': slashes, | ||
'xsl': slashes, | ||
'yaml': hashes | ||
} |
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,115 @@ | ||
|
||
/*#######. | ||
########",#: | ||
#########',##". | ||
##'##'## .##',##. | ||
## ## ## # ##",#. | ||
## ## ## ## ##' | ||
## ## ## :## | ||
## ## ##*/ | ||
|
||
'use strict' | ||
import * as path from 'path' | ||
import * as vscode from 'vscode' | ||
import * as moment from 'moment' | ||
|
||
import { | ||
ExtensionContext, TextEdit, TextEditorEdit, TextDocument, Position, Range | ||
} from 'vscode' | ||
|
||
import { | ||
extractHeader, getHeaderInfo, updateHeaderInfo, renderHeader, | ||
supportsLanguage, IHeaderInfo | ||
} from './header' | ||
|
||
/** | ||
* `insertHeader` Command Handler | ||
*/ | ||
function insertHeaderHandler() { | ||
let activeTextEditor = vscode.window.activeTextEditor | ||
let document = activeTextEditor.document | ||
let languageId = document.languageId | ||
|
||
if (supportsLanguage(languageId)) { | ||
activeTextEditor.edit(editor => { | ||
let currentHeader = extractHeader(document.getText()) | ||
|
||
if (currentHeader) { | ||
let headerInfo = getHeaderInfo(currentHeader) | ||
let updatedHeaderInfo = updateHeaderInfo(headerInfo) | ||
let header = renderHeader(languageId, updatedHeaderInfo) | ||
|
||
editor.replace(new Range(0, 0, 12, 0), header) | ||
} | ||
else { | ||
let user = process.env['USER'] | ||
let headerInfo = { | ||
filename: path.basename(document.fileName), | ||
author: `${user} <${user}@student.42.fr>`, | ||
createdBy: user, | ||
createdAt: moment(), | ||
updatedBy: user, | ||
updatedAt: moment() | ||
} | ||
let header = renderHeader(languageId, headerInfo) | ||
editor.insert(new Position(0, 0), header) | ||
} | ||
}) | ||
} | ||
else | ||
vscode.window.showInformationMessage( | ||
`No header support for language ${languageId}`) | ||
} | ||
|
||
/** | ||
* Start watcher for document save to update current header | ||
* if broken by code-formatter | ||
*/ | ||
function startHeaderUpdateOnSaveWatcher(subscriptions: vscode.Disposable[]) { | ||
const ignoreNextSave = new WeakSet() | ||
|
||
// Here we use the trick from Luke Hoban Go Extension, | ||
// But this will cause an infinite loop if another extension that | ||
// uses the same technique is active. | ||
// And it's really ugly. | ||
vscode.workspace.onDidSaveTextDocument(document => { | ||
let textEditor = vscode.window.activeTextEditor | ||
|
||
if (textEditor.document === document | ||
&& !ignoreNextSave.has(document)) { | ||
let activeTextEditor = vscode.window.activeTextEditor | ||
let languageId = document.languageId | ||
let currentHeader = extractHeader(document.getText()) | ||
|
||
// If current language is supported | ||
// and a header is present at top of document | ||
if (supportsLanguage(languageId) && currentHeader) { | ||
textEditor.edit(editor => { | ||
let headerInfo = getHeaderInfo(currentHeader) | ||
let updatedHeaderInfo = updateHeaderInfo(headerInfo) | ||
let header = renderHeader(languageId, updatedHeaderInfo) | ||
|
||
editor.replace(new Range(0, 0, 12, 0), header) | ||
}) | ||
.then(applied => { | ||
ignoreNextSave.add(document) | ||
return document.save() | ||
}) | ||
.then(() => { | ||
ignoreNextSave.delete(document) | ||
}, err => { }) | ||
} | ||
} | ||
}, null, subscriptions) | ||
} | ||
|
||
export function activate(context: vscode.ExtensionContext) { | ||
let disposable = vscode.commands | ||
.registerTextEditorCommand('42header.insertHeader', insertHeaderHandler) | ||
|
||
context.subscriptions.push(disposable) | ||
startHeaderUpdateOnSaveWatcher(context.subscriptions) | ||
} | ||
|
||
export function deactivate() { | ||
} |
Oops, something went wrong.