1 Star 0 Fork 0

麻本法 / vscode.easy-include

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

easy-include README

Add an include statement to the top of the file from anywhere

Features

  • easyinclude.addInclude: Adds an include statement to the current file

Release Notes

0.0.2

  • The include will now be inserted after #pragma once (if present) if there are no other include statements present

0.0.1

  • First release
  • 一些调整过的部分简要说明

    // 包围计算
        // 不存在包围时,使用 <>
        // >say.h  =>  <say.h>
        // "say.h  =>  "say.h"
        // <say.h> =>  <say.h>
        // "say.h" =>  "say.h"
    
    
    if (value[0] !== '<' && value[0] !== '\"' && value[0] !== '>') {
        value = `<${value}>`;
    } else if (value[0] === '>') {
        value = value.substring(1)
        value = `<${value}>`;
    } else if (value[0] === '"' && value[value.length -1] !== '"') {
        value =  `${value}"`;
    }
    
    // 获取一个有效的编辑器,可能具有焦点,否则不进行处理
        // 获取全文,并使用正则查找一个即将插入的位置
        // /[ \t]* 		任何可能有空格的的开始
        // #\s* 		接着是 # 与可能包含任何空格的部分
        // ()  			抓取一个匹配点
            // 第一种匹配
                // include\s	这个点开头为 include 与单个任意空白
                    // +[<\"]       追加可能的部分  < 或 "
                    // [^>\"]*      紧接着是       非 > 或 " 部分
                    // [>\"]		紧接着是       > 或 " 部分
            // 第二种匹配
                // \s* 			任意空白
                // pragma		紧接着是   pragma (所以这是一个关键点)
                // \s*			任意空白
                // once			紧接着是   once (所以这是一个关键点)
                // \s*			任意空白
    const editor = vscode.window.activeTextEditor;
    if (editor) {
        const text = editor.document.getText();
        const regex = /[ \t]*#\s*(include\s+[<\"][^>\"]*[>\"]\s|\s*pragma\s*once\s)/g;g;
        var match;
    
        // 插入位置
            // 一直接进行向下匹配,如果发现了没有了,这个点就是插入点
        var insertOffset = 0;
        do {
            match = regex.exec(text);
            if (match) {	// 找到结果的搜索的索引
                            // 在索引的起始位置,计算索引的长度并向后移一位
                insertOffset = match.index + match[0].length + 1; 
            }
        } while (match);
    
        editor.edit((editBuilder) => {
            editBuilder.insert(
                editor.document.positionAt(insertOffset),
                `#include ${value}\n`)
        });
    }

空文件

简介

fork https://github.com/soehrl/easy-include 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/zinface/vscode.easy-include.git
git@gitee.com:zinface/vscode.easy-include.git
zinface
vscode.easy-include
vscode.easy-include
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891