* Revert "Revert "Add experimental setting to define where files should be copied for markdown (#169454)" (#169615)"
This reverts commit b2121c2dbe.
* Fix tests
These paths should always use `/`
Fixes#165055
We need to consider the distance between the end of the previous element and start of the next element. Previously we were taking distance from start of the previous to start of the next
* Change descriptions to just say “Enable…”
Previously these said “Enable or disable…”, which in the context of a tick box doesn’t make sense.
* Change “Enable/disable” wording in descriptions
There are two bugs here:
- Something in the lsp is converting a value from `undefined` to `null`. To fix this, I've updated us just to check for falsy values instead
- The `hasInMemoryDoc` implementation was incorrect. It needs to verify that the value of `this.inMemoryDoc` is not null/undefined
Fixes#164562
My previous fix was incorrect as it checked if the document existed by still consulting our `_documentCache`. When we are deleting/renaming an opened md document, it should pretty much always exist in our cache
The fix is to instead treat `this.documents` and the file system as the source of truth when determining if the doc should be deleted or not
* Rework markdown update link glob
Fixes#164587
This changes the `externalFileGlobs` setting to instead be a include array of globs that should trigger link updates. I've split the globs into markdown files and image/video files
This also makes it easier for users to add their own new globs to the list
* Fix scopes
- Picks up newest markdown language service
- Excludes some files from server publish
- Delete unused file
- Update readme
- Align server version with LS version
The `asWebviewUri` methods was introduced in VS Code 1.38. It's silly that we still force every single webview to pay the cost of trying to rewrite the old style uris we supported in very old versions of VS Code
Instead I've moved this logic into the extension host and disabled it for all extensions that target VS Code 1.60+ or newer. This means it never applies to internal webviews, notebooks, webview views, or custom editors (these public apis were all introduced after the switch to `asWebviewUri`)
This expands the list of html tags we allow in markdown. To get this list, I've copied the list of tags from `markdownDocumentRenderer` into `dom` after reviewing them
For #134514, I've also added `video` to the list of allowed tags
Fixes#155552
For lists, the outer ul/ol always has the same source line as the first element in the list. We should prefer using the first element in the list when highlighting the active line
This also fixes a bug where scroll sync would stop working if you added lines to the doc. This was caused by `lineCount` getting out of sync as the document is being updated. I've removed this state and made the reveal logic more robust instead
* Rework how markdown server works with documents
This rewrites how the markdown server works with documents. The goal is to better handle switching between in-memory versions of a doc (from `TextDocument`) and versions of the same doc on disk. From the markdown service's POV, there is only one type of document
As part of this, I've also adopted the newest markdown language service version
* Bump package-lock versions
For #159805
This splits the markdown server into two main functions:
- `startVsCodeServer` which assumes the client can implement all the functionality of VS Code. It is not specific to VS Code however, the client just need to implement the custom messages that VS Code does
- `startServer` which lets you pass in your own implementation of the parser and workspace. A consumer of the server can then use this to have their own custom server implementation, which might use normal node apis to read files
* Use MD LS for resolving all document links
This switches the markdown extension to use the markdown language service when resolving the link. This lets us delete a lot of code that was duplicated between the extension and the LS
* Pick up new ls version
This brings support for code actions and source actions, along with some bug fixes
Also fixes `getAllMarkdownDocuments` to prefer open documents instead of those on disk
Fix markdown link diagnostics not updated when directories are renamed/deleted
Turns our that `createFileSystemWatcher` will not fire if a parent dir is renamed / deleted. See #60813
To fix this, I believe we have to create watchers for all parent directories too (or watch everything in the entire workspace)
* Add experimental support for update markdown links on file moves/renames
Fixes#148146
This adds a new experimental setting that automatically updates markdown
Note that this needs a new version of the vscode-markdown-languageservice so the build is expected to break for now
* Pick up new LS version
* Move MD diagnostics to language server
This switches us to using the LSP pull diagnostic model with a new version of the language service
* Bump package version
* Delete unused file
* Move smart select and folding to md language server
Also fixes a few minor issues:
- Don't log to web console
- Remove convert code since it is no longer needed
- Use correct extension id
* bump cache
* Bump package version
Co-authored-by: João Moreno <joao.moreno@microsoft.com>
* Scaffold out basic markdown lsp
This scaffolds out a new markdown language server and then uses it to implement document symbols. After the change, the markdown extension will have the following structure:
- languageService — Where all the LSP language stuff will eventually land
- server — The actual language server. Consumes ` languageService`
- src — The current extension that launches the server and implements VS Code specific functions
* Adding build scripts
* a
* Use language service from github
* Remove ls build scripts
* Bump versions
* Only build ext
* Enable for web
* Fixing for browser
* Markdown path completions tests use mocked out fs
This updates the path completion tests to stop depending on the actual fs and instead use `IMdWorkspace`
* Update remaining tests
- When splitting `text/uri-list`, we should split on `\n` to handle against spec versions of `text/uri-list`
- However when constructing a `text/uri-list`, we should use `\r\n` to align with the spec
This splits the markdown link tests in two:
- Tests for detecting links in md files (`MdLinkComputer`)
- Tests for the actual vs code editor link provider
Also fixes a few cases splitting these tests up caught
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`
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`
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
* 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
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
* 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
* Improve markdown link regexp
This makes the markdown link regexp more readable and also combines the two regular expressions we were running
* Fixed backtracking
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
(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
* 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`
* Clean up markdown diagnostic tests
This splits the diagnostic compute tests from the test for the diagnostic manager
* Mark internal field as private
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
* 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
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
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`)