Skip to content

Commit f7dcdf9

Browse files
fix: merge current editor options into new ones (#440)
1 parent 4508f61 commit f7dcdf9

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

src/api.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import * as editorconfig from 'editorconfig'
2-
import {
3-
TextDocument,
4-
TextEditorOptions,
5-
Uri,
6-
window,
7-
workspace,
8-
commands,
9-
} from 'vscode'
2+
import { TextDocument, TextEditorOptions, Uri, window, workspace } from 'vscode'
103

114
/**
125
* Resolves `TextEditorOptions` for a `TextDocument`, combining the editor's
@@ -25,7 +18,9 @@ export async function resolveTextEditorOptions(
2518
const coreConfig = await resolveCoreConfig(doc, { onBeforeResolve })
2619
if (coreConfig) {
2720
const defaults = pickWorkspaceDefaults(doc)
28-
return fromEditorConfig(coreConfig, defaults)
21+
const { activeTextEditor: editor } = window
22+
const current = editor?.document === doc ? editor.options : undefined
23+
return fromEditorConfig(coreConfig, defaults, current)
2924
}
3025
if (onEmptyConfig) {
3126
const { relativePath } = resolveFile(doc)
@@ -84,7 +79,6 @@ export function pickWorkspaceDefaults(doc?: TextDocument): {
8479
*/
8580
indentSize?: number | string
8681
} {
87-
commands.executeCommand('editor.action.detectIndentation')
8882
const workspaceConfig = workspace.getConfiguration('editor', doc)
8983
const detectIndentation = workspaceConfig.get<boolean>('detectIndentation')
9084

@@ -151,6 +145,7 @@ export function resolveFile(doc: TextDocument): {
151145
export function fromEditorConfig(
152146
config: editorconfig.KnownProps = {},
153147
defaults: TextEditorOptions = pickWorkspaceDefaults(),
148+
current?: TextEditorOptions,
154149
): TextEditorOptions {
155150
const resolved: TextEditorOptions = {}
156151

@@ -172,7 +167,7 @@ export function fromEditorConfig(
172167
resolved.insertSpaces = true
173168
}
174169

175-
const combined = { ...defaults, ...resolved }
170+
const combined = { ...current, ...defaults, ...resolved }
176171

177172
// decouple tabSize from indentSize when possible
178173
if (

0 commit comments

Comments
 (0)