Commit graph

807 commits

Author SHA1 Message Date
Matt Bierner 07144d22c4
Rename types in the markdown extension (#152905)
Renames in the markdown extension

This renames some types and splits up some files as part of an exploration towards a proper LSP. Changes:

- `SkinnyTextDocument` -> `ITextDocument`
- Moved `ITextDocument` to own file
- `MdWorkspaceContents` -> `IMdWorkspace`
2022-06-22 14:12:48 -07:00
Matt Bierner be1ee5d9f1
Re-validate md files when a linked to file is created or deleted (#152520) 2022-06-22 19:02:46 +00:00
Matt Bierner 321423db2b
Standardize text/uri-list handling (#152756)
This creates a common set of functions for creating and parsing the `text/uri-list` mime type. As part of this, I also aligned us with the standard, which uses `\r\n` between lines instead of just `\n`
2022-06-22 13:53:37 +02:00
Matt Bierner 5437480941
Enable md paste actions by default (#152810)
Turns on pasting of links for easier testing. However `editor.experimental.pasteActions.enabled` is still off by default so this won't be enabled by default
2022-06-22 08:19:52 +02:00
Matt Bierner c84655d123
Reduce recomputation of state in markdown extension (#152804)
* Reduce recomputation of state in markdown extension

- Use `getForDocument` more often to avoid refetching documents
- Debounce `MdTableOfContentsWatcher`. We don't want this to trigger on every keystroke :)

* Cache LinkDefinitionSet

* Add test file change

* Fix toc watcher for tests
2022-06-21 16:25:10 -07:00
Matt Bierner 389aa8a935
Fix MdDocumentInfoCache computing values twice (#152799)
* Fix MdDocumentInfoCache computing values twice

Fixes a race where values could be computed twice before being cached

* Remove only
2022-06-21 16:22:07 -07:00
Matt Bierner d5a75f2ceb
Add logging for MD language features (#152792)
This verbose logging will help track down inefficient calling patterns (such as recomputing stuff)
2022-06-21 14:18:36 -07:00
Matt Bierner bbe7b54cf4
Remove custom editor tests (#152777)
These tests are not actively being run or maintained. Removing them for now
2022-06-21 15:37:19 -04:00
Matt Bierner fa53aa6fec
Cleanup pass for md extension (#152760)
Clean up names in md extension
2022-06-21 15:36:32 -04:00
Matt Bierner 2249b171f4
Reduce number of times MD docs are re-tokenized (#152674)
This change reduces the number of times we retokenize a markdown file by doing the following:

- Use `MdTableOfContentsProvider` in more places
- Introduce a `IMarkdownParser` interface that lets us drop in a caching version of the tokenizer
2022-06-21 08:43:01 +02:00
Matt Bierner 369252a027
Skip diagnostics for non-open md files (#152687)
Currently we only show diagnostics for opened tabs. This means we shouldn't waste time computing diagnostics for these non open files
2022-06-20 16:39:01 -07:00
Matt Bierner 0bc3109761
Don't try parsing non-markdown files (#152661)
This fixes our references and rename provider to not try parsing non-markdown files as if they were markdown
2022-06-20 10:44:50 -07:00
Matt Bierner 4c72dedb4a
Optimize markdown workspace scanning (#152563)
* Optimize markdown workspace scanning

- Adds cache for markdown file
- Avoid reading non-markdown files from disk (when we expect markdown files)
- Use `range.contains(pos)` instead of `range.intersects(range)`

* Don't remove cached document on change

We only want to invalidate the cached document when it is first opened (since the cached version is the one from disk). Otherwise we can use the live version of the doc
2022-06-19 09:40:10 -07:00
Matt Bierner 5a175207de
Improve markdown link regexp (#152533)
* Improve markdown link regexp

This makes the markdown link regexp more readable and also combines the two regular expressions we were running

* Fixed backtracking
2022-06-19 06:25:54 +02:00
Matt Bierner 78597fd026
Don't hardcode use of github slugifier (#152507)
Use `engine.slugifier` for this instead
2022-06-17 17:25:54 -04:00
Matt Bierner dea813ff7c
Add table of contents provider abstraction (#152504)
We currently re-compute the same table of contents for markdown files multiple times. This is because multiple language features all need table of contents

With this change, we introduce a new `TableOfContentsProvider` which maintains a cache of the table of contents per file. This provider is then passed into every caller that needs a toc
2022-06-17 18:20:02 +00:00
Matt Bierner 623f55f437
Refactor markdown language features (#152402)
(sorry for the size of this PR)

This change cleans up the markdown language features by making the following changes:

- Use `registerXSupport` public functions to register these
- Expose the slugifier the `MarkdownEngine` uses. You never want to use a different one if you already have a markdown engine
- Sort of clean up names. I'd introduced a bunch of confusing names while iterating in this space. What I'm working towards:

    - `Computer` — Stateless thing that computer data
    - `Provider` — Potentially stateful thing that provides data (which may be cached)
    - `VsCodeProvider` — The actual implementation of the various vscode language features (which should only be used by VS Code and in tests, not shared with other features)
- Introduce `MdLinkProvider` to avoid recomputing links for a given document. Also use this to hide more internals of link computation
2022-06-17 10:25:52 +02:00
Matt Bierner afe316c08c
Add diagnostic manager enablement change tests (#152392)
* Add test for MD diagnostic manager config changes

Add a simple test the enabling/disable diagnostics should make the diagnostic manager recompute diagnostics

* Add `.get`
2022-06-16 15:53:19 -07:00
Matt Bierner cb5fa75d11
Clean up markdown diagnostic tests (#152374)
* Clean up markdown diagnostic tests

This splits the diagnostic compute tests from the test for the diagnostic manager

* Mark internal field as private
2022-06-16 22:33:11 +02:00
Matt Bierner 3114ee690b
Split out VS Code reference provider from markdown reference provider (#152369)
This change renames the main markdown reference provider class to `MdReferenceComputer` and then uses this to implement a `vscode.ReferenceProvider`

This more cleanly splits the VS Code part of the logic from the general reference calculation stuff other providers consume
2022-06-16 15:47:48 -04:00
Matt Bierner 6c252851f2
Revalidate linked files on header change (#152366)
Fixes #150945

With this change, when the headers in a file change, we should also try to revalidate all files that link to it
2022-06-16 18:14:01 +00:00
Matt Bierner 4fc5d76213
Fix ranges and validation setting for MD own path + header links (#152270)
* Fix ranges and validation setting for MD own path + header links

Previously for a `file.md`, links to headers in that file that use paths, such as `[link](./file.md#some-header)` were validated using `markdown.experimental.validate.fragmentLinks.enabled`

This is confusing as that setting was only meant to be used for links such as`[link](#some-header`). It also resulted in the diagnostic having the incorrect range

This change instead makes these links be validated by `markdown.experimental.validate.fileLinks.markdownFragmentLinks`

* Fix compile
2022-06-15 20:02:41 -07:00
Matt Bierner a765abcf07
Adopt ResourceMap for MD diagnostics (#152264)
Adopt ResourceMap

Switches to use `ResourceMap` instead of our own implementation
2022-06-15 15:43:09 -07:00
Matt Bierner f17b33faf2
Use .?method() in more places (#152112)
Switches simple patterns like:

```ts
if (some.thing) {
    some.thing.method();
}
```

to:

```ts
some.thing?.method()
```

This is more concise and avoids having to repeat the `some.thing` part
2022-06-15 16:28:31 +00:00
Matt Bierner 354e1a0595
Finalize data file reading API (#152127)
Fixes #147481
Also reverts #150963 since the `kind` field is not being finalized
2022-06-15 07:56:02 -07:00
Matt Bierner 00273730e8
Split markdown linkComputer from linkProvider (#152124)
Instead of passing around a full `vscode.DocumentLinkProvider`, we should pass just the more minimal interface that consumers need
2022-06-14 15:34:05 -07:00
Matt Bierner 00574df08a
Remove extra path field in FileLinksData (#152004)
Remove extra `path` field

This field is no longer needed after we switched to use `ResourceMap` vs `Map`

Also inlines the `FileLinksData` type def
2022-06-14 08:01:53 -07:00
Matt Bierner a658c04b0a
Adjust md external header link diagnostic range (#152001)
Fixes #151998

Makes errors for invalid headers on file links only cover the fragment range instead of the entire link range
2022-06-14 09:39:49 +02:00
Matt Bierner 1a07fd15d7
Clarify markdown validate settings (#151997)
Clairify markdown validate settings

Fixes #150949

- Rename headerLinks -> fragmentLinks
- Add new `fileLink.markdownFragmentsLinks` to validate the headers on fragment links (inherits the default setting value from `fragmentLinks`)
2022-06-13 17:06:28 -07:00
Matt Bierner 7284c3e4c1
Use classes for drop/paste edit types (#151980) 2022-06-13 13:10:07 -07:00
Johannes ed9ed45794
Merge branch 'main' into joh/voluminous-lobster 2022-06-10 09:07:30 +02:00
Babak K. Shandiz a8de8e2112
[markdown] Ignore brackets inside link text (#151610)
* 🔨 Allow texts in bracket pairs inside link titles; [text](link)

Signed-off-by: GitHub <noreply@github.com>

* 🔨 Allow texts in bracket pairs inside link titles; [text](<link>)

Signed-off-by: GitHub <noreply@github.com>

* ⚗️ Add tests to verify  link titles can include bracket pairs

Signed-off-by: GitHub <noreply@github.com>
2022-06-09 11:48:50 -07:00
Johannes 3622010b64
Merge branch 'main' into joh/voluminous-lobster 2022-06-09 09:08:20 +02:00
Matt Bierner d7c90c2b2b
Update text editor drop proposal (#151552)
This updates the text editor drop proposal (#142990). This change introduces `DocumentDropEdit` which removes the need for `SnippetTextEdit`. This interface may also be extended in the future with additional metadata
2022-06-08 17:44:28 -04:00
Matt Bierner 48cfaa2187
Fix rename of paths in markdown reference link definitions (#151545)
Fixes #151117
2022-06-08 19:20:17 +00:00
Matt Bierner 370dfd5fee
Iterate on paste edit provider api (#151477)
* Iterate on paste edit provider api

For #30066

- Pass all selections to paste providers. For #151326
- Introduce `DocumentPasteEdit` as return type. This new type uses an `insertText` that is applied to every paste location (for multicursor), plus an optional additional edit
-  Add `DocumentPasteProviderMetadata`. This lets extensions tell us which types of mimetypes they are interested in, letting us avoid round trips if no extensions care about the pasted data

* Correctly batch insertText
2022-06-08 15:06:55 -04:00
Johannes 0656d21d11
auto-fixed prefer-const violation 2022-06-08 17:49:21 +02:00
Matt Bierner 1327d1eb50
Adopt ResourceMap in more places (#151475)
This changes switches to use the new `ResourceMap` type in more places in the markdown extension where we need to have a map/set with uris as the key
2022-06-08 08:34:06 +02:00
Matt Bierner 60a68d666d
Add resourceMap helper for markdown extension (#151471)
This change introduces a `ResoruceMap` map type that is essentially `Map<vscode.Uri, T>`

It also fixes a potential race condition with `MdWorkspaceCache` where two quick calls would both trigger init
2022-06-07 18:00:10 -07:00
Matt Bierner 9545af80f6
Fix markdown link detection for links with titles (#151459)
Fixes #151458
2022-06-07 20:58:29 +00:00
Justin Chen bcc7ffae3e
bugfix on markdown underlines, addressing part of issue #136073 (#151178)
Co-authored-by: Justin Chen <t-justinchen@microsoft.com>
Co-authored-by: Matt Bierner <matb@microsoft.com>
2022-06-06 17:35:41 +00:00
Logan Ramos 70647a2ffd
Fix #150041 (#151108) 2022-06-02 11:02:26 -04:00
Matt Bierner e44f4ba886
Add experimental tag to experimental extension settings (#151031)
This makes a few more extension settings with the `experimental` tag so that show up if you search `@tag:experimental`
2022-06-01 16:32:58 -07:00
Matt Bierner 9302343e8e
Also ignore star checkboxes (#151029)
Fixes #150672

This makes our md link detection also ignore checkboxes like `* [x]` instead of just `- [x]`
2022-06-01 21:23:29 +00:00
Matt Bierner 7477efd87e
Better message for markdown reference links (#151018)
Fixes #151017

Also improves the diagnostic message for invalid reference links to make it clear we are talking about a missing link definition
2022-06-01 19:01:36 +00:00
Matt Bierner e6fff5ecff
Don't parse checkboxes are links in markdown (#150914)
Fixes #150672
2022-05-31 14:57:32 -07:00
Matt Bierner e4f7f6a9da
Add PasteEditProvider (#107283)
For #30066

This adds a new `documentPaste` api proposal that lets extensions hook into copy and paste.

This can be used to do things such as:

- Create link when pasting an image
- Bring along imports when copy and pasting code
2022-05-25 12:27:58 +02:00
Matt Bierner 1c7991f1e8
Markdown ignoreLink should apply to paths in header links (#150223)
This change lets you ignore all links to a given file, even if those links include a header. For example: `[text](/path/to/file#some-header)` can be ignored using `/path/to/file`
2022-05-23 17:07:15 -07:00
Matt Bierner b8420578fd
Add additional allowed tags in untrusted notebook markdown (#150228)
This adds some extra allowed tags when rendering markdown in notebooks. Additions are:

```
  "b",

    "br",

    "caption",

    "center",

    "col",

    "colgroup",

    "details",

    "em",

    "font",

    "i",

    "kbd",

    "sub",

    "summary",

    "sup",

    "table",

    "tbody",

    "tfoot",

    "thead",

    "td",

    "th",

    "tr",

    "tt",

    "u",

    "video"
```
2022-05-23 22:30:42 +00:00
Matt Bierner 96cae45ba9
Rename skipPaths to ignoreLinks (#150064)
This change renames the experimental skipPaths setting to ignoreLinks. This setting applies to all types of links, and can also be used to ignore links to headers
2022-05-20 22:54:21 +00:00