tofile

Project definition

  • For the convenience of this project, the middle double arrow mode area below the file is calledFragment
/*\ ## Technical point |*| - R: |*| - [VSCode Open a File In a Specific Line Number Using JS](https://stackoverflow.com/questions/62453615/vscode-open-a-file-in-a-specific-line-number-using-js) |*| - [Capturing  keystrokes in visual studio code extension](https://stackoverflow.com/questions/36727520/capturing-keystrokes-in-visual-studio-code-extension#answer-3675 3622) |*| - [How to open file and insert text using the VSCode API](https://stackoverflow.com/questions/38279920/how-to-open-file-and-insert-text-using-the-vscode-api) \*/Copy the code

features

  1. Using the commandtofileIs probed for a string containing a relative path in the current cursor line (likesrc/a.ts:2:3Among them2Is the line number, 3 is the column number, the column is optional), and attempts to open jump in VSCode
  • Tofile (F1 input tofile) will retrieve a string with a relative path for the current cursor line to open the file with VSCode and jump

2. CompletionFragment

  • Known issues
    • Before normal typing delete* | |Will appear (this is not an issue in Vim normal mode)

    • Solution: Normal typing selects the entire line and deletes it

    • Why is this a problem

      1. Vscode does not support multiple extension registration type commands, which results in only one extension being able to fine-grained control keyboard events
      1. And I don’t want tofile to be that complicated
      • Multiple extensions registering the ‘type’ command

The VSCode extension tofile itself has no dependencies that you might have when using a script in the repository

  • src/script/fragment.tsRely onts-node ripgrep
  • yarn fragmentnpm run fragmentWill generatets-Fragments.md(File name extension + fragment.md) in the project root directory. Projects are another example.
  • yarn fragmentnpm run fragmentThe script ists-node -P ./tsconfig.json ./src/script/fragment.ts tsWhen you use the TS script, you need to specifytsconfig.json, the path of the script and a file name suffix type, here ists

Use Fragment

  • When using literal regular expressions* /Will be an error
    • Can’t use literal Regex
      • An example
      /*\ ## only match space |*| ' \n'.match(/^\x20*/A \ * /Copy the code
      • Solution: Use workarounds
      /*\ ## only match space |*| ```ts |*| ' \n'.match(new RegExp(String.raw`^\x20*`)) |*| ``` \*/
      Copy the code

Build a reason

  • When you’re writing a large project, there are all kinds of questions.
  • Usually, it is a reference to find the answer to a similar problem through a search engine. (This step is omitted when you can solve it yourself, but there is often more than one solution to the problem. There are often things to watch out for.)
  • Just isolate the points above
    • The problem
    • Multiple solutions
    • reference
    • Matters needing attention
  • These things can be made into a template in a canonical Markdown format
> < p style = "max-width: 100%; clear: both;

< p style = "text-align: center;

> A: Answers (solution)

> R: Reference


## How to interrupt for
- N:
  > aaaa
- A:
  - aaaa
  - bbbb
- R:
  - [Interrupt the for] (https://****.com)
  - [Interrupt the for] (https://****.com)
Copy the code
  • It can also be abbreviated as pass the following rule
    • Title indicates problem
    • Nothing means we don’t have it right now
    • >Syntax stands for what to do
    • Each one-line list represents a solution
    • A one-line list is a reference for links
## How to interrupt for
> aaaa
- aaaa
- bbbb
- [Interrupt the for] (https://****.com)
- [Interrupt the for] (https://****.com)
Copy the code
  • However, this is only applicable to Markdown files, and the template writing method is only to record the pattern of the problem, when the problem does not occur, it will become laborious and useless
  • So I don’t want to make big changes to the existing situation, but to establish new writing habits.
  • The new custom is to write the template from Markdown above into code comments like TypeScript/JavaScript
  • Write code comments that look like (italics for nuggets)
/ * \ # # interrupt ` forof ` | | * > can only be used in * | | - throw new Error (' ') | | * - break * | | - [interrupt for] (https:// * * * *. Com) \ * /
Copy the code
  • Why use this format/ * | \ \ | * * /
    • You know intuitively in the code that this is aFragment
    • In editors such as VSCode, you can directly support the collapse of comment blocks. After the collapse, only one line of questions will be displayed to make the code cleaner

  • The template writing in Markdown above is easy to do with snippets (such as vscode snippet)
  • The template writing method in Markdown above, written to the code file, hasbenefit
    • QARN (Question and Answers, Reference, Note) with the code in one place, rectify.
    • If the project is correct, the problem is solved
    • It’s very native to dive into code quickly
  • However, write the template from Markdown above into the code commentsdisadvantagesis
    • By dispersing the myriad problems into small files within the project,
    • Not good for retrieval
    • Not conducive to summarizing records
  • Hence the project Tofile
  • throughripgrepPull out the problems in the individual code files, record the location of the files in the project, and generate a Markdown file with the nature of a directory.
  • This is easy to do with any script,
  • But this script is just a summary of the record retrieval behavior that should be put into the editor.
  • So tofile does that