Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- AWS
- Docker
- vue login
- 로그인
- database
- 프론트
- react-query
- Git
- 기획
- 회고록
- vuex
- 토이프로젝트
- 배포
- vue
- 플러그인
- 뷰
- plugin
- extension
- express
- react
- 신상마켓
- jwt
- login
- 셋팅
- javascript
- vsCode
- nginx
- PWA
- 정리
- Firebase
Archives
- Today
- Total
강디너의 개발 일지
Vscode Extension (플러그인) 만들기_2 본문
728x90
Vscode Extension (플러그인) 만들기_2
MD 파일의 문자 개수 측정하는 플러그인 예제
vscode page -> https://code.visualstudio.com/docs/extensions/example-word-count
우선 다시 폴더를 만들어주시고
extesion.ts 함수입니다.
계속 Hello World 만 쳐야 하는게 싫어서 Hi 로 바꿔봤습니다.
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import { window, commands, Disposable, ExtensionContext, StatusBarAlignment, StatusBarItem, TextDocument } from 'vscode';
// This method is called when your extension is activated. Activation is
// controlled by the activation events defined in package.json.
export function activate(context: ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error).
// This line of code will only be executed once when your extension is activated.
console.log('Congratulations, your extension "WordCount" is now active!');
// create a new word counter
let wordCounter = new WordCounter();
// sayHello 를 sayHi 함수로 변경
let disposable = commands.registerCommand('extension.sayHi', () => {
wordCounter.updateWordCount();
});
// Add to a list of disposables which are disposed when this extension is deactivated.
context.subscriptions.push(wordCounter);
context.subscriptions.push(disposable);
}
class WordCounter {
private _statusBarItem: StatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left);
public updateWordCount() {
// Get the current text editor
let editor = window.activeTextEditor;
if (!editor) {
this._statusBarItem.hide();
return;
}
let doc = editor.document;
// Only update status if a Markdown file
// markdown 체크
if (doc.languageId === "markdown") {
let wordCount = this._getWordCount(doc);
// Update the status bar
this._statusBarItem.text = wordCount !== 1 ? `${wordCount} Words` : '1 Word';
this._statusBarItem.show();
} else {
this._statusBarItem.hide();
}
}
public _getWordCount(doc: TextDocument): number {
let docContent = doc.getText();
// Parse out unwanted whitespace so the split is accurate
docContent = docContent.replace(/(< ([^>]+)<)/g, '').replace(/\s+/g, ' ');
docContent = docContent.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
let wordCount = 0;
if (docContent !== "") {
wordCount = docContent.split(" ").length;
}
return wordCount;
}
dispose() {
this._statusBarItem.dispose();
}
}
JSON 파일도 수정해줍니다.
JSON 은 주석이 안되서 사진만 빠르게..
이제 HI 라고 쳐도 반응을 합니다 !
아래에 3단어라고 표시됩니다.
Hi 라고 호출해야지 Words 가 표시되는데
자동으로 쭉 ~ 표시되는 방법은 다음편에 계속하겠습니다.
반응형
'Javascript > 삽질' 카테고리의 다른 글
| GraphQL 이란 (0) | 2018.12.02 |
|---|---|
| 디자인 패턴 : Flux (0) | 2018.11.26 |
| 디자인 패턴 : MVC (0) | 2018.11.23 |
| Vscode Extension (플러그인) 만들기_3 (0) | 2018.11.23 |
| Vscode Extension (플러그인) 만들기_1 (2) | 2018.11.20 |
Comments