Skip to content

Commit 72e2ecf

Browse files
committed
Add quarto.symbols.exportToWorkspace LSP setting
1 parent b260250 commit 72e2ecf

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

apps/lsp/src/config.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ export interface Settings {
4343
readonly scale: number;
4444
readonly extensions: MathjaxSupportedExtension[];
4545
}
46+
readonly symbols: {
47+
readonly exportToWorkspace: 'default' | 'all' | 'none';
48+
};
4649
};
4750
readonly markdown: {
4851
readonly preferredMdPathExtensionStyle: 'auto' | 'includeExtension' | 'removeExtension';
@@ -88,6 +91,9 @@ function defaultSettings(): Settings {
8891
mathjax: {
8992
scale: 1,
9093
extensions: []
94+
},
95+
symbols: {
96+
exportToWorkspace: 'all'
9197
}
9298
},
9399
markdown: {
@@ -165,6 +171,9 @@ export class ConfigurationManager extends Disposable {
165171
mathjax: {
166172
scale: settings.quarto.mathjax.scale,
167173
extensions: settings.quarto.mathjax.extensions
174+
},
175+
symbols: {
176+
exportToWorkspace: settings.quarto.symbols.exportToWorkspace
168177
}
169178
}
170179
};
@@ -224,12 +233,13 @@ export function lsConfiguration(configManager: ConfigurationManager): LsConfigur
224233
},
225234
get mathjaxExtensions(): readonly MathjaxSupportedExtension[] {
226235
return configManager.getSettings().quarto.mathjax.extensions;
236+
},
237+
get exportSymbolsToWorkspace(): 'default' | 'all' | 'none' {
238+
return configManager.getSettings().quarto.symbols.exportToWorkspace;
227239
}
228240
}
229241
}
230242

231-
232-
233243
export function getDiagnosticsOptions(configManager: ConfigurationManager): DiagnosticOptions {
234244
const settings = configManager.getSettings();
235245
if (!settings) {

apps/lsp/src/service/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export interface LsConfiguration {
7979
readonly colorTheme: 'light' | 'dark';
8080
readonly mathjaxScale: number;
8181
readonly mathjaxExtensions: readonly MathjaxSupportedExtension[];
82+
readonly exportSymbolsToWorkspace: 'default' | 'all' | 'none';
8283
}
8384

8485
export const defaultMarkdownFileExtension = 'qmd';
@@ -109,7 +110,8 @@ const defaultConfig: LsConfiguration = {
109110
includeWorkspaceHeaderCompletions: 'never',
110111
colorTheme: 'light',
111112
mathjaxScale: 1,
112-
mathjaxExtensions: []
113+
mathjaxExtensions: [],
114+
exportSymbolsToWorkspace: 'all'
113115
};
114116

115117
export function defaultLsConfiguration(): LsConfiguration {

apps/lsp/src/service/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export function createLanguageService(init: LanguageServiceInitialization): IMdL
209209
const diagnosticOnSaveComputer = new DiagnosticOnSaveComputer(init.quarto);
210210
const diagnosticsComputer = new DiagnosticComputer(config, init.workspace, linkProvider, tocProvider, logger);
211211
const docSymbolProvider = new MdDocumentSymbolProvider(tocProvider, linkProvider, logger);
212-
const workspaceSymbolProvider = new MdWorkspaceSymbolProvider(init.workspace, docSymbolProvider);
212+
const workspaceSymbolProvider = new MdWorkspaceSymbolProvider(init.workspace, init.config, docSymbolProvider);
213213
const documentHighlightProvider = new MdDocumentHighlightProvider(config, tocProvider, linkProvider);
214214

215215
return Object.freeze<IMdLanguageService>({

apps/lsp/src/service/providers/workspace-symbols.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,32 @@
1414
*
1515
*/
1616

17+
import * as fs from 'fs';
18+
import { Utils } from 'vscode-uri';
1719
import { CancellationToken } from 'vscode-languageserver';
1820
import * as lsp from 'vscode-languageserver-types';
1921
import { Disposable } from 'core';
2022
import { Document } from 'quarto-core';
2123
import { IWorkspace } from '../workspace';
2224
import { MdWorkspaceInfoCache } from '../workspace-cache';
2325
import { MdDocumentSymbolProvider } from './document-symbols';
26+
import { LsConfiguration } from '../config';
2427

2528
export class MdWorkspaceSymbolProvider extends Disposable {
26-
29+
readonly #config: LsConfiguration;
2730
readonly #cache: MdWorkspaceInfoCache<readonly lsp.SymbolInformation[]>;
2831
readonly #symbolProvider: MdDocumentSymbolProvider;
32+
readonly #workspace: IWorkspace;
2933

3034
constructor(
3135
workspace: IWorkspace,
36+
config: LsConfiguration,
3237
symbolProvider: MdDocumentSymbolProvider,
3338
) {
3439
super();
40+
41+
this.#workspace = workspace;
42+
this.#config = config;
3543
this.#symbolProvider = symbolProvider;
3644

3745
this.#cache = this._register(new MdWorkspaceInfoCache(workspace, (doc, token) => this.provideDocumentSymbolInformation(doc, token)));
@@ -42,6 +50,12 @@ export class MdWorkspaceSymbolProvider extends Disposable {
4250
return [];
4351
}
4452

53+
switch (this.#config.exportSymbolsToWorkspace) {
54+
case 'all': break;
55+
case 'default': if (shouldExportSymbolsToWorkspace(this.#workspace)) return []; else break;
56+
case 'none': return [];
57+
}
58+
4559
const allSymbols = await this.#cache.values();
4660

4761
if (token.isCancellationRequested) {
@@ -73,3 +87,17 @@ export class MdWorkspaceSymbolProvider extends Disposable {
7387
}
7488
}
7589
}
90+
91+
function shouldExportSymbolsToWorkspace(workspace: IWorkspace): boolean {
92+
return isRPackage(workspace);
93+
}
94+
95+
function isRPackage(workspace: IWorkspace): boolean {
96+
if (workspace.workspaceFolders === undefined) {
97+
return false;
98+
}
99+
100+
const projectPath = workspace.workspaceFolders[0];
101+
const descPath = Utils.joinPath(projectPath, 'DESCRIPTION');
102+
return fs.existsSync(descPath.fsPath);
103+
}

apps/vscode/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,17 @@
13191319
"error"
13201320
],
13211321
"markdownDescription": "Log level for the Quarto language server."
1322+
},
1323+
"quarto.symbols.exportToWorkspace": {
1324+
"type": "string",
1325+
"enum": ["default", "all", "none"],
1326+
"enumDescriptions": [
1327+
"Depends on the project type: `\"none\"` in R packages, `\"all\"` otherwise.",
1328+
"",
1329+
""
1330+
],
1331+
"default": "default",
1332+
"description": "Whether Markdown elements like section headers are included in workspace symbol search."
13221333
}
13231334
}
13241335
},

apps/vscode/src/lsp/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*
1414
*/
1515

16+
import * as fs from "fs";
1617
import * as path from "path";
1718
import {
1819
ExtensionContext,

0 commit comments

Comments
 (0)