Skip to content

Commit

Permalink
Merge branch 'main' into support-three-or-more-chords
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedgreen authored Mar 8, 2023
2 parents 8bd1a68 + da15b03 commit decf8c1
Show file tree
Hide file tree
Showing 106 changed files with 1,512 additions and 952 deletions.
14 changes: 14 additions & 0 deletions .github/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,20 @@
"addLabel": "*caused-by-extension",
"comment": "It looks like this is caused by the Codespaces extension. Please file the issue in the [Codespaces Discussion Forum](http://aka.ms/ghcs-feedback). Make sure to check their issue reporting template and provide them relevant information such as the extension version you're using. See also our [issue reporting guidelines](https://aka.ms/vscodeissuereporting) for more information.\n\nHappy Coding!"
},
{
"type": "comment",
"name": "extCopilot",
"allowUsers": [
"cleidigh",
"usernamehw",
"gjsjohnmurray",
"IllusionMH"
],
"action": "close",
"reason": "not_planned",
"addLabel": "*caused-by-extension",
"comment": "It looks like this is caused by the Copilot extension. Please file the issue in the [Copilot Discussion Forum](https://github.com/community/community/discussions/categories/copilot). Make sure to check their issue reporting template and provide them relevant information such as the extension version you're using. See also our [issue reporting guidelines](https://aka.ms/vscodeissuereporting) for more information.\n\nHappy Coding!"
},
{
"type": "comment",
"name": "gifPlease",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/locker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ jobs:
daysSinceClose: 45
appInsightsKey: ${{secrets.TRIAGE_ACTIONS_APP_INSIGHTS}}
daysSinceUpdate: 3
ignoredLabel: "*out-of-scope"
ignoredLabel: "*out-of-scope,accessibility"
ignoreLabelUntil: "author-verification-requested"
labelUntil: "verified"
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,6 @@
},
"githubPullRequests.assignCreated": "${user}",
"githubPullRequests.defaultMergeMethod": "squash",
"application.experimental.rendererProfiling": true
"application.experimental.rendererProfiling": true,
"editor.experimental.asyncTokenization": true
}
3 changes: 2 additions & 1 deletion build/monaco/monaco.d.ts.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export interface ICommandHandler {
#includeAll(vs/editor/common/model): IScrollEvent
#include(vs/editor/common/diff/smartLinesDiffComputer): IChange, ICharChange, ILineChange
#include(vs/editor/common/diff/documentDiffProvider): IDocumentDiffProvider, IDocumentDiffProviderOptions, IDocumentDiff
#include(vs/editor/common/diff/linesDiffComputer): LineRangeMapping, LineRange, RangeMapping
#include(vs/editor/common/core/lineRange): LineRange
#include(vs/editor/common/diff/linesDiffComputer): LineRangeMapping, RangeMapping
#include(vs/editor/common/core/dimension): IDimension
#includeAll(vs/editor/common/editorCommon): IScrollEvent
#includeAll(vs/editor/common/textModelEvents):
Expand Down
15 changes: 8 additions & 7 deletions extensions/github/src/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,11 @@ function getFileAndPosition(context: LinkContext): IFilePosition | INotebookPosi
const cell = vscode.window.activeNotebookEditor.notebook.getCells().find(cell => cell.document.uri.fragment === uri?.fragment);
const cellIndex = cell?.index ?? vscode.window.activeNotebookEditor.selection.start;

let range;
if (lineNumber !== undefined) {
range = new vscode.Range(new vscode.Position(lineNumber - 1, 0), new vscode.Position(lineNumber - 1, 1));
} else if (cell !== undefined) {
range = vscode.window.activeTextEditor?.selection;
}
const range = getRangeOrSelection(lineNumber);
return { type: LinkType.Notebook, uri, cellIndex, range };
} else {
// the active editor is a text editor
range = lineNumber !== undefined ? new vscode.Range(lineNumber - 1, 0, lineNumber - 1, 1) : vscode.window.activeTextEditor?.selection;
range = getRangeOrSelection(lineNumber);
return { type: LinkType.File, uri, range };
}
}
Expand All @@ -91,6 +86,12 @@ function getFileAndPosition(context: LinkContext): IFilePosition | INotebookPosi
return undefined;
}

function getRangeOrSelection(lineNumber: number | undefined) {
return lineNumber !== undefined && (!vscode.window.activeTextEditor || vscode.window.activeTextEditor.selection.isEmpty || !vscode.window.activeTextEditor.selection.contains(new vscode.Position(lineNumber - 1, 0)))
? new vscode.Range(lineNumber - 1, 0, lineNumber - 1, 1)
: vscode.window.activeTextEditor?.selection;
}

function rangeString(range: vscode.Range | undefined) {
if (!range) {
return '';
Expand Down
1 change: 1 addition & 0 deletions extensions/markdown-language-features/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
server/
11 changes: 11 additions & 0 deletions extensions/markdown-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,17 @@
"default": "off",
"description": "%markdown.trace.server.desc%"
},
"markdown.server.log": {
"type": "string",
"scope": "window",
"enum": [
"off",
"debug",
"trace"
],
"default": "off",
"description": "%markdown.server.log.desc%"
},
"markdown.editor.drop.enabled": {
"type": "boolean",
"default": true,
Expand Down
1 change: 1 addition & 0 deletions extensions/markdown-language-features/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"markdown.showPreviewSecuritySelector.title": "Change Preview Security Settings",
"markdown.trace.extension.desc": "Enable debug logging for the Markdown extension.",
"markdown.trace.server.desc": "Traces the communication between VS Code and the Markdown language server.",
"markdown.server.log.desc": "Controls the logging level of the Markdown language server.",
"markdown.preview.refresh.title": "Refresh Preview",
"markdown.preview.toggleLock.title": "Toggle Preview Locking",
"markdown.findAllFileReferences": "Find File References",
Expand Down
26 changes: 16 additions & 10 deletions extensions/markdown-language-features/preview-src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getEditorLineNumberForPageOffset, scrollToRevealSourceLine, getLineElem
import { SettingsManager, getData } from './settings';
import throttle = require('lodash.throttle');
import morphdom from 'morphdom';
import type { ToWebviewMessage } from '../types/previewMessaging';

let scrollDisabledCount = 0;

Expand All @@ -21,13 +22,17 @@ let documentResource = settings.settings.source;

const vscode = acquireVsCodeApi();

const originalState = vscode.getState();
const originalState = vscode.getState() ?? {} as any;

const state = {
...(typeof originalState === 'object' ? originalState : {}),
originalState,
...getData<any>('data-state')
};

if (originalState?.resource !== state.resource) {
state.scrollProgress = undefined;
}

// Make sure to sync VS Code state here
vscode.setState(state);

Expand Down Expand Up @@ -114,24 +119,25 @@ window.addEventListener('resize', () => {
}, true);

window.addEventListener('message', async event => {
switch (event.data.type) {
const data = event.data as ToWebviewMessage.Type;
switch (data.type) {
case 'onDidChangeTextEditorSelection':
if (event.data.source === documentResource) {
marker.onDidChangeTextEditorSelection(event.data.line, documentVersion);
if (data.source === documentResource) {
marker.onDidChangeTextEditorSelection(data.line, documentVersion);
}
return;

case 'updateView':
if (event.data.source === documentResource) {
onUpdateView(event.data.line);
if (data.source === documentResource) {
onUpdateView(data.line);
}
return;

case 'updateContent': {
const root = document.querySelector('.markdown-body')!;

const parser = new DOMParser();
const newContent = parser.parseFromString(event.data.content, 'text/html');
const newContent = parser.parseFromString(data.content, 'text/html');

// Strip out meta http-equiv tags
for (const metaElement of Array.from(newContent.querySelectorAll('meta'))) {
Expand All @@ -140,9 +146,9 @@ window.addEventListener('message', async event => {
}
}

if (event.data.source !== documentResource) {
if (data.source !== documentResource) {
root.replaceWith(newContent.querySelector('.markdown-body')!);
documentResource = event.data.source;
documentResource = data.source;
} else {
const skippedAttrs = [
'open', // for details
Expand Down
17 changes: 12 additions & 5 deletions extensions/markdown-language-features/preview-src/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@
*--------------------------------------------------------------------------------------------*/

import { SettingsManager } from './settings';
import type { FromWebviewMessage } from '../types/previewMessaging';

export interface MessagePoster {
/**
* Post a message to the markdown extension
*/
postMessage(type: string, body: object): void;
postMessage<T extends FromWebviewMessage.Type>(
type: T['type'],
body: Omit<T, 'source' | 'type'>
): void;
}

export const createPosterForVsCode = (vscode: any, settingsManager: SettingsManager) => {
return new class implements MessagePoster {
postMessage(type: string, body: object): void {
export const createPosterForVsCode = (vscode: any, settingsManager: SettingsManager): MessagePoster => {
return {
postMessage<T extends FromWebviewMessage.Type>(
type: T['type'],
body: Omit<T, 'source' | 'type'>
): void {
vscode.postMessage({
type,
source: settingsManager.settings!.source,
body
...body
});
}
};
Expand Down
4 changes: 2 additions & 2 deletions extensions/markdown-language-features/server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-markdown-languageserver",
"description": "Markdown language server",
"version": "0.3.0-alpha.4",
"version": "0.3.0-alpha.6",
"author": "Microsoft Corporation",
"license": "MIT",
"engines": {
Expand All @@ -18,7 +18,7 @@
"vscode-languageserver": "^8.0.2",
"vscode-languageserver-textdocument": "^1.0.5",
"vscode-languageserver-types": "^3.17.1",
"vscode-markdown-languageservice": "^0.3.0-alpha.5",
"vscode-markdown-languageservice": "^0.3.0-alpha.6",
"vscode-uri": "^3.0.3"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export type ValidateEnabled = 'ignore' | 'warning' | 'error' | 'hint';

export interface Settings {
readonly markdown: {
readonly server: {
readonly log: 'off' | 'debug' | 'trace';
};

readonly preferredMdPathExtensionStyle: 'auto' | 'includeExtension' | 'removeExtension';

readonly occurrencesHighlight: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function registerValidateSupport(
const emptyDiagnosticsResponse = Object.freeze({ kind: 'full', items: [] });

connection.languages.diagnostics.on(async (params, token): Promise<FullDocumentDiagnosticReport | UnchangedDocumentDiagnosticReport> => {
logger.log(md.LogLevel.Trace, 'Server: connection.languages.diagnostics.on', params.textDocument.uri);
logger.log(md.LogLevel.Debug, 'connection.languages.diagnostics.on', { document: params.textDocument.uri });

if (!config.getSettings()?.markdown.validate.enabled) {
return emptyDiagnosticsResponse;
Expand Down
50 changes: 42 additions & 8 deletions extensions/markdown-language-features/server/src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ILogger, LogLevel } from 'vscode-markdown-languageservice';
import * as md from 'vscode-markdown-languageservice';
import { ConfigurationManager } from './configuration';
import { Disposable } from './util/dispose';

export class LogFunctionLogger implements ILogger {
export class LogFunctionLogger extends Disposable implements md.ILogger {

private static now(): string {
const now = new Date();
Expand All @@ -27,21 +29,53 @@ export class LogFunctionLogger implements ILogger {
return JSON.stringify(data, undefined, 2);
}

private _logLevel: md.LogLevel;

constructor(
private readonly _logFn: typeof console.log
) { }
private readonly _logFn: typeof console.log,
private readonly _config: ConfigurationManager,
) {
super();

this._register(this._config.onDidChangeConfiguration(() => {
this._logLevel = LogFunctionLogger.readLogLevel(this._config);
}));

this._logLevel = LogFunctionLogger.readLogLevel(this._config);
}

private static readLogLevel(config: ConfigurationManager): md.LogLevel {
switch (config.getSettings()?.markdown.server.log) {
case 'trace': return md.LogLevel.Trace;
case 'debug': return md.LogLevel.Debug;
case 'off':
default:
return md.LogLevel.Off;
}
}

get level(): md.LogLevel { return this._logLevel; }

public log(level: LogLevel, title: string, message: string, data?: any): void {
this.appendLine(`[${level} ${LogFunctionLogger.now()}] ${title}: ${message}`);
public log(level: md.LogLevel, message: string, data?: any): void {
if (this.level < level) {
return;
}

this.appendLine(`[${this.toLevelLabel(level)} ${LogFunctionLogger.now()}] ${message}`);
if (data) {
this.appendLine(LogFunctionLogger.data2String(data));
}
}

private toLevelLabel(level: md.LogLevel): string {
switch (level) {
case md.LogLevel.Off: return 'Off';
case md.LogLevel.Debug: return 'Debug';
case md.LogLevel.Trace: return 'Trace';
}
}

private appendLine(value: string): void {
this._logFn(value);
}
}

export const consoleLogger = new LogFunctionLogger(console.log);
15 changes: 8 additions & 7 deletions extensions/markdown-language-features/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ interface MdServerInitializationOptions extends LsConfiguration { }
const organizeLinkDefKind = 'source.organizeLinkDefinitions';

export async function startVsCodeServer(connection: Connection) {
const logger = new LogFunctionLogger(connection.console.log.bind(connection.console));
const configurationManager = new ConfigurationManager(connection);
const logger = new LogFunctionLogger(connection.console.log.bind(connection.console), configurationManager);

const parser = new class implements md.IMdParser {
slugifier = md.githubSlugifier;
Expand All @@ -41,7 +42,7 @@ export async function startVsCodeServer(connection: Connection) {
return workspace;
};

return startServer(connection, { documents, notebooks, logger, parser, workspaceFactory });
return startServer(connection, { documents, notebooks, configurationManager, logger, parser, workspaceFactory });
}

type WorkspaceFactory = (config: {
Expand All @@ -53,6 +54,7 @@ type WorkspaceFactory = (config: {
export async function startServer(connection: Connection, serverConfig: {
documents: TextDocuments<md.ITextDocument>;
notebooks?: NotebookDocuments<md.ITextDocument>;
configurationManager: ConfigurationManager;
logger: md.ILogger;
parser: md.IMdParser;
workspaceFactory: WorkspaceFactory;
Expand All @@ -62,7 +64,6 @@ export async function startServer(connection: Connection, serverConfig: {
let mdLs: md.IMdLanguageService | undefined;

connection.onInitialize((params: InitializeParams): InitializeResult => {
const configurationManager = new ConfigurationManager(connection);
const initOptions = params.initializationOptions as MdServerInitializationOptions | undefined;

const mdConfig = getLsConfiguration(initOptions ?? {});
Expand All @@ -74,7 +75,7 @@ export async function startServer(connection: Connection, serverConfig: {
logger: serverConfig.logger,
...mdConfig,
get preferredMdPathExtensionStyle() {
switch (configurationManager.getSettings()?.markdown.preferredMdPathExtensionStyle) {
switch (serverConfig.configurationManager.getSettings()?.markdown.preferredMdPathExtensionStyle) {
case 'includeExtension': return md.PreferredMdPathExtensionStyle.includeExtension;
case 'removeExtension': return md.PreferredMdPathExtensionStyle.removeExtension;
case 'auto':
Expand All @@ -84,9 +85,9 @@ export async function startServer(connection: Connection, serverConfig: {
}
});

registerCompletionsSupport(connection, documents, mdLs, configurationManager);
registerDocumentHighlightSupport(connection, documents, mdLs, configurationManager);
registerValidateSupport(connection, workspace, documents, mdLs, configurationManager, serverConfig.logger);
registerCompletionsSupport(connection, documents, mdLs, serverConfig.configurationManager);
registerDocumentHighlightSupport(connection, documents, mdLs, serverConfig.configurationManager);
registerValidateSupport(connection, workspace, documents, mdLs, serverConfig.configurationManager, serverConfig.logger);

return {
capabilities: {
Expand Down
Loading

0 comments on commit decf8c1

Please sign in to comment.