0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VSCodeの拡張を自作する:2_文章を取得する

Posted at

この記事について

概要は
概要のページ
をご確認ください。

この記事で出来ることは、エディタのテキストを読み取ってポップアップに表示するところまでです。

エディタ操作

基本的な操作になるようなものは、大体vscode.window配下にいる。

Windowの構造

ドキュメントの該当箇所

大体こんな構造になっている

  • vscode
    • window
      • activeTextEditor (:TextEditor):現在フォーカスされているエディタ(タブ)
        • document (:TextDocument):エディタ内の本文とか
      • visibleTextEditors (:TextEditor[]):表示されているすべてのエディタ(タブ)
      • activeTerminal (:Terminal):表示されているターミナル

表示中の文章等はvscode.window.activeTextEditor.document.getText()で取得できます。

文章を取得してポップアップに表示するサンプル


	//フォーカスされてるエディタの選択文字列を表示
	let testCommand1 = vscode.commands.registerCommand('vscodeExtensionTest.command1', () => {
		const editor:vscode.TextEditor | undefined = vscode.window.activeTextEditor;
		if ( editor !== undefined ){
			const document:vscode.TextDocument = editor.document;
			const selection:vscode.Selection = editor.selection;
			const word:string = document.getText(selection);
			vscode.window.showInformationMessage(word);
		}
	});
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?