Skip to content

Commit

Permalink
[INTERNAL] Update to vscode 1.66.2
Browse files Browse the repository at this point in the history
  • Loading branch information
GehDoc committed Sep 4, 2022
1 parent 8bddd89 commit c9648a6
Show file tree
Hide file tree
Showing 20 changed files with 129 additions and 86 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [INTERNAL] Correct importing files with spaces from vscode repository

### Changed
- [INTERNAL] Prepare update to vscode 1.66.2
- [INTERNAL] Update to vscode 1.66.2


## [1.3.19] - 20220627
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
"version": "1.3.19",
"icon": "media/textile-mark_logo.png",
"publisher": "GehDoc",
"repository": {
"type": "git",
"url": "https://github.com/GehDoc/vscode-textile-preview.git"
},
"license": "SEE LICENSE IN LICENSE.txt",
"engines": {
"node" : ">=16.0.0",
"vscode": "^1.65.0"
"vscode": "^1.66.0"
},
"main": "./dist/extension",
"browser": "./dist/browser/extension",
Expand Down Expand Up @@ -363,15 +359,16 @@
"url": "https://liberapay.com/GehDoc/donate"
},
"dependencies": {
"highlight.js": "^10.4.1",
"highlight.js": "^11.4.0",
"morphdom": "^2.6.1",
"vscode-nls": "^5.0.0"
"vscode-nls": "^5.0.0",
"vscode-uri": "^3.0.3"
},
"devDependencies": {
"@types/lodash.throttle": "^4.1.3",
"@types/mocha": "^9.1.1",
"@types/node": "16.x",
"@types/vscode": "^1.65.0",
"@types/vscode": "^1.66.0",
"@types/vscode-webview": "^1.57.0",
"copy-webpack-plugin": "^6.0.3",
"del": "^4.1.1",
Expand All @@ -396,5 +393,9 @@
"@vscode/test-electron": "^2.1.3",
"webpack": "^5.42.0",
"webpack-cli": "^4.7.2"
},
"repository": {
"type": "git",
"url": "https://github.com/GehDoc/vscode-textile-preview.git"
}
}
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { CommandManager } from './commandManager';
import * as commands from './commands/index';
import LinkProvider from './features/documentLinkProvider';
import TextileDocumentSymbolProvider from './features/documentSymbolProvider';
// import { registerDropIntoEditor } from './features/dropIntoEditor';
import TextileFoldingProvider from './features/foldingProvider';
import { PathCompletionProvider } from './features/pathCompletions';
import { TextileContentProvider } from './features/previewContentProvider';
Expand Down Expand Up @@ -51,6 +52,8 @@ export function activate(context: vscode.ExtensionContext) {
logger.updateConfiguration();
previewManager.updateConfiguration();
}));

// FIXME : context.subscriptions.push(registerDropIntoEditor());
}

function registerTextileLanguageFeatures(
Expand Down
12 changes: 6 additions & 6 deletions src/features/documentLinkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import * as uri from 'vscode-uri';
import { OpenDocumentLinkCommand } from '../commands/openDocumentLink';
import { Token } from '../../libs/textile-js/textile';
import { TextileEngine, getLineNumber, getEndLineNumber } from '../textileEngine';
import { getUriForLinkWithKnownExternalScheme, isOfScheme, Schemes } from '../util/links';
import { dirname } from '../util/path';

const localize = nls.loadMessageBundle();

Expand Down Expand Up @@ -48,7 +48,7 @@ function parseLink(
resourceUri = vscode.Uri.joinPath(root, tempUri.path);
}
} else {
const base = document.uri.with({ path: dirname(document.uri.fsPath) });
const base = uri.Utils.dirname(document.uri);
resourceUri = vscode.Uri.joinPath(base, tempUri.path);
}
}
Expand Down Expand Up @@ -147,7 +147,7 @@ function compareLinkRanges(a: vscode.DocumentLink, b: vscode.DocumentLink): numb
const linkPattern = /("(?!\s)((?:[^"]|"(?![\s:])[^\n"]+"(?!:))+)":)((?:[^\s()]|\([^\s()]+\)|[()])+?)(?=[!-\.:-@\[\\\]-`{-~]+(?:$|\s)|$|\s)|(\["([^\n]+?)":)((?:\[[a-z0-9]*\]|[^\]])+)\]/g
const imagePattern = /(!(?!\s)((?:\([^\)]+\)|\{[^\}]+\}|\\[[^\[\]]+\]|(?:<>|<|>|=)|[\(\)]+)*(?:\.[^\n\S]|\.(?:[^\.\/]))?)([^!\s]+?) ?(?:\(((?:[^\(\)]|\([^\(\)]+\))+)\))?!)(?::([^\s]+?(?=[!-\.:-@\[\\\]-`{-~](?:$|\s)|\s|$)))?/g
/* Disabled : not relevant for textile
const referenceLinkPattern = /(\[((?:\\\]|[^\]])+)\]\[\s*?)([^\s\]]*?)\]/g;
const referenceLinkPattern = /(?:(\[((?:\\\]|[^\]])+)\]\[\s*?)([^\s\]]*?)\]|\[\s*?([^\s\]]*?)\])(?!\:)/g;
*/
const definitionPattern = /^\[([^\]]+)\]((?:https?:\/\/|[.]{1,2}\/|#)\S+)(?:\s*(?=\n)|$)/gm;
const inlineCodePattern = /(?:^|[^@])(@+)(?:.+?|.*?(?:(?:\r?\n).+?)*?)(?:\r?\n)?\1(?:$|[^@])/gm;
Expand Down Expand Up @@ -284,11 +284,11 @@ export default class LinkProvider implements vscode.DocumentLinkProvider {
const offset = (match.index || 0) + pre.length;
linkStart = document.positionAt(offset);
linkEnd = document.positionAt(offset + reference.length);
} else if (match[2]) { // [ref][]
reference = match[2];
} else if (match[4]) { // [ref][], [ref]
reference = match[4];
const offset = (match.index || 0) + 1;
linkStart = document.positionAt(offset);
linkEnd = document.positionAt(offset + match[2].length);
linkEnd = document.positionAt(offset + reference.length);
} else {
continue;
}
Expand Down
13 changes: 10 additions & 3 deletions src/features/pathCompletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ interface CompletionContext {
readonly anchorInfo?: AnchorContext;
}

function tryDecodeUriComponent(str: string): string {
try {
return decodeURIComponent(str);
} catch {
return str;
}
}
export class PathCompletionProvider implements vscode.CompletionItemProvider {

public static register(selector: vscode.DocumentSelector, engine: TextileEngine): vscode.Disposable {
Expand Down Expand Up @@ -90,7 +97,7 @@ export class PathCompletionProvider implements vscode.CompletionItemProvider {

case CompletionContextKind.LinkDefinition:
case CompletionContextKind.Link: {
const items: vscode.CompletionItem[] = Array.from(this.provideReferenceSuggestions(document, position, context));
const items: vscode.CompletionItem[] = Array.from(this.provideReferenceSuggestions(document, position, context)); // Modified for Textile

const isAnchorInCurrentDoc = context.anchorInfo && context.anchorInfo.beforeAnchor.length === 0;

Expand Down Expand Up @@ -162,7 +169,7 @@ export class PathCompletionProvider implements vscode.CompletionItemProvider {
const suffix = lineSuffixText.match(/^[^\s]*/); // Changed for Textile
return {
kind: CompletionContextKind.Link,
linkPrefix: prefix,
linkPrefix: tryDecodeUriComponent(prefix),
linkTextStartPosition: position.translate({ characterDelta: -prefix.length }),
linkSuffix: suffix ? suffix[0] : '',
anchorInfo: this.getAnchorContext(prefix),
Expand All @@ -179,7 +186,7 @@ export class PathCompletionProvider implements vscode.CompletionItemProvider {
const suffix = lineSuffixText.match(/^[^\s]*/);
return {
kind: CompletionContextKind.LinkDefinition,
linkPrefix: prefix,
linkPrefix: tryDecodeUriComponent(prefix),
linkTextStartPosition: position.translate({ characterDelta: -prefix.length }),
linkSuffix: suffix ? suffix[0] : '',
anchorInfo: this.getAnchorContext(prefix),
Expand Down
38 changes: 7 additions & 31 deletions src/features/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import * as uri from 'vscode-uri';
import { Logger } from '../logger';
import { TextileEngine } from '../textileEngine';
import { TextileContributionProvider } from '../textileExtensions';
import { Disposable } from '../util/dispose';
import { isTextileFile } from '../util/file';
import { openDocumentLink, resolveDocumentLink, resolveUriToTextileFile } from '../util/openDocumentLink';
import * as path from '../util/path';
import { WebviewResourceProvider } from '../util/resources';
import { getVisibleLine, LastScrollLocation, TopmostLineMonitor } from '../util/topmostLineMonitor';
import { urlToUri } from '../util/url';
Expand Down Expand Up @@ -177,31 +177,6 @@ class TextilePreview extends Disposable implements WebviewResourceProvider {
}
}));

this._register(this._webviewPanel.onDidChangeViewState(async () => {
if (this._disposed) {
return;
}

if (this._webviewPanel.active) {
let document: vscode.TextDocument;
try {
document = await vscode.workspace.openTextDocument(this._resource);
} catch {
return;
}

if (this._disposed) {
return;
}

const content = await this._contentProvider.provideTextDocumentContent(document, this, this._previewConfigurations, this.line, this.state);
if (!this._webviewPanel.active && !this._disposed) {
// Update the html so we can show it properly when restoring it
this._webviewPanel.webview.html = content.html;
}
}
}));

this._register(this._webviewPanel.webview.onDidReceiveMessage((e: CacheImageSizesMessage | RevealLineMessage | DidClickMessage | ClickLinkMessage | ShowPreviewSecuritySelectorMessage | PreviewStyleLoadErrorMessage) => {
if (e.source !== this._resource.toString()) {
return;
Expand Down Expand Up @@ -339,7 +314,7 @@ class TextilePreview extends Disposable implements WebviewResourceProvider {
return;
}

const shouldReloadPage = forceUpdate || !this.currentVersion || this.currentVersion.resource.toString() !== pendingVersion.resource.toString();
const shouldReloadPage = forceUpdate || !this.currentVersion || this.currentVersion.resource.toString() !== pendingVersion.resource.toString() || !this._webviewPanel.visible;
this.currentVersion = pendingVersion;
const content = await (shouldReloadPage
? this._contentProvider.provideTextDocumentContent(document, this, this._previewConfigurations, this.line, this.state)
Expand Down Expand Up @@ -421,7 +396,7 @@ class TextilePreview extends Disposable implements WebviewResourceProvider {
const srcs = new Set(containingImages.map(img => img.src));

// Delete stale file watchers.
for (const [src, watcher] of [...this._fileWatchersBySrc]) {
for (const [src, watcher] of this._fileWatchersBySrc) {
if (!srcs.has(src)) {
watcher.dispose();
this._fileWatchersBySrc.delete(src);
Expand Down Expand Up @@ -460,7 +435,7 @@ class TextilePreview extends Disposable implements WebviewResourceProvider {
baseRoots.push(...workspaceRoots);
}
} else {
baseRoots.push(this._resource.with({ path: path.dirname(this._resource.path) }));
baseRoots.push(uri.Utils.dirname(this._resource));
}

return baseRoots;
Expand Down Expand Up @@ -786,9 +761,10 @@ export class DynamicTextilePreview extends Disposable implements ManagedTextileP
}

private static getPreviewTitle(resource: vscode.Uri, locked: boolean): string {
const resourceLabel = uri.Utils.basename(resource);
return locked
? localize('lockedPreviewTitle', '[Preview] {0}', path.basename(resource.fsPath))
: localize('previewTitle', 'Preview {0}', path.basename(resource.fsPath));
? localize('lockedPreviewTitle', '[Preview] {0}', resourceLabel)
: localize('previewTitle', 'Preview {0}', resourceLabel);
}

public get position(): vscode.ViewColumn | undefined {
Expand Down
8 changes: 4 additions & 4 deletions src/features/previewContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import * as uri from 'vscode-uri';
import { Logger } from '../logger';
import { TextileEngine } from '../textileEngine';
import { TextileContributionProvider } from '../textileExtensions';
import { ContentSecurityPolicyArbiter, TextilePreviewSecurityLevel } from '../security';
import { basename, dirname, isAbsolute, join } from '../util/path';
import { WebviewResourceProvider } from '../util/resources';
import { TextilePreviewConfiguration, TextilePreviewConfigurationManager } from './previewConfig';

Expand Down Expand Up @@ -127,7 +127,7 @@ export class TextileContentProvider {
public provideFileNotFoundContent(
resource: vscode.Uri,
): string {
const resourcePath = basename(resource.fsPath);
const resourcePath = uri.Utils.basename(resource);
const body = localize('preview.notFound', '{0} cannot be found', resourcePath);
return `<!DOCTYPE html>
<html>
Expand All @@ -153,7 +153,7 @@ export class TextileContentProvider {
}

// Assume it must be a local file
if (isAbsolute(href)) {
if (href.startsWith('/') || /^[a-z]:\\/i.test(href)) {
return resourceProvider.asWebviewUri(vscode.Uri.file(href)).toString();
}

Expand All @@ -164,7 +164,7 @@ export class TextileContentProvider {
}

// Otherwise look relative to the textile file
return resourceProvider.asWebviewUri(vscode.Uri.file(join(dirname(resource.fsPath), href))).toString();
return resourceProvider.asWebviewUri(vscode.Uri.joinPath(uri.Utils.dirname(resource), href)).toString();
}

private computeCustomStyleSheetIncludes(resourceProvider: WebviewResourceProvider, resource: vscode.Uri, config: TextilePreviewConfiguration): string {
Expand Down
2 changes: 1 addition & 1 deletion src/features/previewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class TextilePreviewManager extends Disposable implements vscode.WebviewP
document: vscode.TextDocument,
webview: vscode.WebviewPanel
): Promise<void> {
const lineNumber = this._topmostLineMonitor.getPreviousTextEditorLineByUri(document.uri);
const lineNumber = this._topmostLineMonitor.getPreviousStaticTextEditorLineByUri(document.uri);
const preview = StaticTextilePreview.revive(
document.uri,
webview,
Expand Down
2 changes: 1 addition & 1 deletion src/test/documentLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function getLinksForFile(file: vscode.Uri): Promise<vscode.DocumentLink[]>
return r;
}

suite('Textile Document links', () => {
(vscode.env.uiKind === vscode.UIKind.Web ? suite.skip : suite)('Textile Document links', () => {

setup(async () => {
// the tests make the assumption that link providers are already registered
Expand Down
31 changes: 31 additions & 0 deletions src/test/documentLinkProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,37 @@ suite('textile.DocumentLinkProvider', () => {
assert.strictEqual(links.length, 0);
});

// https://github.com/microsoft/vscode/issues/141285
test('Should only find one link for reference sources [a]source (#141285)', async () => {
const links = await getLinksForFile([
'[Works]https://microsoft.com',
].join('\n'));

assert.strictEqual(links.length, 1);
});

// https://github.com/microsoft/vscode/issues/141285
test('Should find links for referees with only one [] (#141285)', async () => {
// Textile finds only one link
let links = await getLinksForFile([
'[ref]',
'[ref]https://microsoft.com',
].join('\n'));
assert.strictEqual(links.length, 1);

links = await getLinksForFile([
'[Does Not Work]',
'[def]https://microsoft.com',
].join('\n'));
assert.strictEqual(links.length, 1);
});

// https://github.com/microsoft/vscode/issues/141285
test('Should not find link for reference using one [] when source does not exist (#141285)', async () => {
const links = await getLinksForFile('[Works]');
assert.strictEqual(links.length, 0);
});

test('Should not consider links in code fenced with bc.', async () => {
const text = joinLines(
'bc. b is',
Expand Down
5 changes: 2 additions & 3 deletions src/test/foldingProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
*--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import * as vscode from 'vscode';
import 'mocha';

import * as vscode from 'vscode';
import TextileFoldingProvider from '../features/foldingProvider';
import { InMemoryDocument } from './inMemoryDocument';
import { createNewTextileEngine } from './engine';
import { InMemoryDocument } from './inMemoryDocument';

const testFileName = vscode.Uri.file('test.md');

Expand Down
1 change: 1 addition & 0 deletions src/test/inMemoryDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class InMemoryDocument implements vscode.TextDocument {
const before = this._contents.slice(0, offset);
const newLines = before.match(/\r\n|\n/g);
const line = newLines ? newLines.length : 0;
// eslint-disable-next-line code-no-look-behind-regex
const preCharacters = before.match(/(?<=\r\n|\n|^).*$/g);
return new vscode.Position(line, preCharacters ? preCharacters[0].length : 0);
}
Expand Down
Loading

0 comments on commit c9648a6

Please sign in to comment.