Skip to content

Commit 784bbda

Browse files
authored
Allowing configuring if markdown inserts a .md when completing paths to markdown files (microsoft#174882)
Fixes microsoft#174005
1 parent 05abefc commit 784bbda

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

extensions/markdown-language-features/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,21 @@
582582
"additionalProperties": {
583583
"type": "string"
584584
}
585+
},
586+
"markdown.preferredMdPathExtensionStyle": {
587+
"type": "string",
588+
"default": "auto",
589+
"markdownDescription": "%configuration.markdown.preferredMdPathExtensionStyle%",
590+
"enum": [
591+
"auto",
592+
"includeExtension",
593+
"removeExtension"
594+
],
595+
"markdownEnumDescriptions": [
596+
"%configuration.markdown.preferredMdPathExtensionStyle.auto%",
597+
"%configuration.markdown.preferredMdPathExtensionStyle.includeExtension%",
598+
"%configuration.markdown.preferredMdPathExtensionStyle.removeExtension%"
599+
]
585600
}
586601
}
587602
},

extensions/markdown-language-features/package.nls.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,9 @@
5454
"configuration.markdown.updateLinksOnFileMove.enableForDirectories": "Enable updating links when a directory is moved or renamed in the workspace.",
5555
"configuration.markdown.occurrencesHighlight.enabled": "Enable highlighting link occurrences in the current document.",
5656
"configuration.markdown.copyFiles.destination": "Defines where files copied into a Markdown document should be created. This is a map from globs that match on the Markdown document to destinations.\n\nThe destinations may use the following variables:\n\n- `${documentFileName}` — The full filename of the Markdown document, for example `readme.md`.\n- `${documentBaseName}` — The basename of Markdown document, for example `readme`.\n- `${documentExtName}` — The extension of the Markdown document, for example `md`.\n- `${documentDirName}` — The name of the Markdown document's parent directory.\n- `${documentWorkspaceFolder}` — The workspace folder for the Markdown document, for examples, `/Users/me/myProject`. This is the same as `${documentDirName}` if the file is not part of in a workspace.\n- `${fileName}` — The file name of the dropped file, for example `image.png`.",
57+
"configuration.markdown.preferredMdPathExtensionStyle": "Controls if file extensions (e.g. `.md`) are added or not for links to Markdown files. This setting is used when file paths are added by tooling such as path completions or file renames.",
58+
"configuration.markdown.preferredMdPathExtensionStyle.auto": "For existing paths, try to maintain the file extension style. For new paths, add file extensions.",
59+
"configuration.markdown.preferredMdPathExtensionStyle.includeExtension": "Prefer including the file extension. For example, path completions to a file named `file.md` will insert `file.md`.",
60+
"configuration.markdown.preferredMdPathExtensionStyle.removeExtension": "Prefer removing the file extension. For example, path completions to a file named `file.md` will insert `file` without the `.md`.",
5761
"workspaceTrust": "Required for loading styles configured in the workspace."
5862
}

extensions/markdown-language-features/server/src/configuration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export type ValidateEnabled = 'ignore' | 'warning' | 'error' | 'hint';
1010

1111
export interface Settings {
1212
readonly markdown: {
13+
readonly preferredMdPathExtensionStyle: 'auto' | 'includeExtension' | 'removeExtension';
14+
1315
readonly occurrencesHighlight: {
1416
readonly enabled: boolean;
1517
};

extensions/markdown-language-features/server/src/server.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,26 @@ export async function startServer(connection: Connection, serverConfig: {
6262
let mdLs: md.IMdLanguageService | undefined;
6363

6464
connection.onInitialize((params: InitializeParams): InitializeResult => {
65+
const configurationManager = new ConfigurationManager(connection);
6566
const initOptions = params.initializationOptions as MdServerInitializationOptions | undefined;
66-
const config = getLsConfiguration(initOptions ?? {});
6767

68-
const configurationManager = new ConfigurationManager(connection);
68+
const mdConfig = getLsConfiguration(initOptions ?? {});
6969

70-
const workspace = serverConfig.workspaceFactory({ connection, config, workspaceFolders: params.workspaceFolders });
70+
const workspace = serverConfig.workspaceFactory({ connection, config: mdConfig, workspaceFolders: params.workspaceFolders });
7171
mdLs = md.createLanguageService({
7272
workspace,
7373
parser: serverConfig.parser,
7474
logger: serverConfig.logger,
75-
markdownFileExtensions: config.markdownFileExtensions,
76-
excludePaths: config.excludePaths,
75+
...mdConfig,
76+
get preferredMdPathExtensionStyle() {
77+
switch (configurationManager.getSettings()?.markdown.preferredMdPathExtensionStyle) {
78+
case 'includeExtension': return md.PreferredMdPathExtensionStyle.includeExtension;
79+
case 'removeExtension': return md.PreferredMdPathExtensionStyle.removeExtension;
80+
case 'auto':
81+
default:
82+
return md.PreferredMdPathExtensionStyle.auto;
83+
}
84+
}
7785
});
7886

7987
registerCompletionsSupport(connection, documents, mdLs, configurationManager);

0 commit comments

Comments
 (0)