Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook up new markdown workspace header suggestion setting #174004

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions extensions/markdown-language-features/package.json
Expand Up @@ -401,6 +401,22 @@
"description": "%configuration.markdown.suggest.paths.enabled.description%",
"scope": "resource"
},
"markdown.suggest.paths.includeWorkspaceHeaderCompletions": {
"type": "string",
"default": "onDoubleHash",
"scope": "resource",
"markdownDescription": "%configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions%",
"enum": [
"never",
"onDoubleHash",
"onSingleOrDoubleHash"
],
"markdownEnumDescriptions": [
"%configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions.never%",
"%configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions.onDoubleHash%",
"%configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions.onSingleOrDoubleHash%"
]
},
"markdown.trace.extension": {
"type": "string",
"enum": [
Expand Down
4 changes: 4 additions & 0 deletions extensions/markdown-language-features/package.nls.json
Expand Up @@ -31,6 +31,10 @@
"configuration.markdown.links.openLocation.currentGroup": "Open links in the active editor group.",
"configuration.markdown.links.openLocation.beside": "Open links beside the active editor.",
"configuration.markdown.suggest.paths.enabled.description": "Enable path suggestions while writing links in Markdown files.",
"configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions": "Enable suggestions for headers in other Markdown files in the current workspace. Accepting one of these suggestions inserts the full path to header in that file, for example `[link text](/path/to/file.md#header)`.",
"configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions.never": "Disable workspace header suggestions.",
"configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions.onDoubleHash": "Enable workspace header suggestions after typing `##` in a path, for example `[link text](##`.",
"configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions.onSingleOrDoubleHash": "Enable workspace header suggestions after typing either `##` or `#` in a path, for example `[link text](#` or `[link text](##`.",
"configuration.markdown.editor.drop.enabled": "Enable dropping files into a Markdown editor while holding Shift. Requires enabling `#editor.dropIntoEditor.enabled#`.",
"configuration.markdown.editor.pasteLinks.enabled": "Enable pasting files into a Markdown editor inserts Markdown links. Requires enabling `#editor.experimental.pasteActions.enabled#`.",
"configuration.markdown.validate.enabled.description": "Enable all error reporting in Markdown files.",
Expand Down
Expand Up @@ -17,6 +17,7 @@ export interface Settings {
readonly suggest: {
readonly paths: {
readonly enabled: boolean;
readonly includeWorkspaceHeaderCompletions: 'never' | 'onSingleOrDoubleHash' | 'onDoubleHash';
};
};

Expand Down
14 changes: 13 additions & 1 deletion extensions/markdown-language-features/server/src/server.ts
Expand Up @@ -283,6 +283,15 @@ function registerCompletionsSupport(
ls: md.IMdLanguageService,
config: ConfigurationManager,
): IDisposable {
function getIncludeWorkspaceHeaderCompletions(): md.IncludeWorkspaceHeaderCompletions {
switch (config.getSettings()?.markdown.suggest.paths.includeWorkspaceHeaderCompletions) {
case 'onSingleOrDoubleHash': return md.IncludeWorkspaceHeaderCompletions.onSingleOrDoubleHash;
case 'onDoubleHash': return md.IncludeWorkspaceHeaderCompletions.onDoubleHash;
case 'never':
default: return md.IncludeWorkspaceHeaderCompletions.never;
}
}

connection.onCompletion(async (params, token): Promise<lsp.CompletionItem[]> => {
const settings = config.getSettings();
if (!settings?.markdown.suggest.paths.enabled) {
Expand All @@ -292,7 +301,10 @@ function registerCompletionsSupport(
const document = documents.get(params.textDocument.uri);
if (document) {
// TODO: remove any type after picking up new release with correct types
return ls.getCompletionItems(document, params.position, { ...params.context!, includeWorkspaceHeaderCompletions: md.IncludeWorkspaceHeaderCompletions.onDoubleHash, } as any, token);
return ls.getCompletionItems(document, params.position, {
...(params.context || {}),
includeWorkspaceHeaderCompletions: getIncludeWorkspaceHeaderCompletions(),
} as any, token);
}
return [];
});
Expand Down
Expand Up @@ -2048,7 +2048,7 @@ function cleanRenderedMarkdown(element: Node): void {
}

function fixSettingLinks(text: string, linkify = true): string {
return text.replace(/`#([^#]*)#`|'#([^#]*)#'/g, (match, backticksGroup, quotesGroup) => {
return text.replace(/`#([^#\s`]+)#`|'#([^#\s']+)#'/g, (match, backticksGroup, quotesGroup) => {
const settingKey: string = backticksGroup ?? quotesGroup;
const targetDisplayFormat = settingKeyToDisplayFormat(settingKey);
const targetName = `${targetDisplayFormat.category}: ${targetDisplayFormat.label}`;
Expand Down