Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { CursorChangeReason } from 'vs/editor/common/cursorEvents';
import { autorun, autorunDelta, constObservable, debouncedObservable, derived, IObservable, observableFromEvent, observableFromPromise, wasEventTriggeredRecently } from 'vs/base/common/observable';
import { AudioCue, IAudioCueService } from 'vs/platform/audioCues/browser/audioCueService';
import { CachedFunction } from 'vs/base/common/cache';
import { Position } from 'vs/editor/common/core/position';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';

export class AudioCueLineFeatureContribution
extends Disposable
Expand All @@ -40,7 +42,8 @@ export class AudioCueLineFeatureContribution
constructor(
@IEditorService private readonly editorService: IEditorService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IAudioCueService private readonly audioCueService: IAudioCueService
@IAudioCueService private readonly audioCueService: IAudioCueService,
@IConfigurationService private readonly _configurationService: IConfigurationService
) {
super();

Expand Down Expand Up @@ -89,7 +92,7 @@ export class AudioCueLineFeatureContribution
editorModel: ITextModel,
store: DisposableStore
): void {
const curLineNumber = observableFromEvent(
const curPosition = observableFromEvent(
editor.onDidChangeCursorPosition,
(args) => {
/** @description editor.onDidChangeCursorPosition (caused by user) */
Expand All @@ -101,11 +104,10 @@ export class AudioCueLineFeatureContribution
// Ignore cursor changes caused by navigation (e.g. which happens when execution is paused).
return undefined;
}
return editor.getPosition()?.lineNumber;
return editor.getPosition();
}
);
const debouncedLineNumber = debouncedObservable(curLineNumber, 300, store);

const debouncedPosition = debouncedObservable(curPosition, this._configurationService.getValue('audioCues.debouncePositionChanges') ? 300 : 0, store);
const isTyping = wasEventTriggeredRecently(
editorModel.onDidChangeContent.bind(editorModel),
1000,
Expand All @@ -120,25 +122,26 @@ export class AudioCueLineFeatureContribution
if (!this.isEnabledCache.get(feature.audioCue).read(reader)) {
return false;
}
const lineNumber = debouncedLineNumber.read(reader);
return lineNumber === undefined
? false
: lineFeatureState.read(reader).isPresent(lineNumber);
const position = debouncedPosition.read(reader);
if (!position) {
return false;
}
return lineFeatureState.read(reader).isPresent(position);
}
);
return derived(
`typingDebouncedFeatureState:\n${feature.audioCue.name}`,
(reader) =>
feature.debounceWhileTyping && isTyping.read(reader)
? (debouncedLineNumber.read(reader), isFeaturePresent.get())
? (debouncedPosition.read(reader), isFeaturePresent.get())
: isFeaturePresent.read(reader)
);
});

const state = derived(
'states',
(reader) => ({
lineNumber: debouncedLineNumber.read(reader),
lineNumber: debouncedPosition.read(reader),
featureStates: new Map(
this.features.map((feature, idx) => [
feature,
Expand Down Expand Up @@ -172,7 +175,7 @@ interface LineFeature {
}

interface LineFeatureState {
isPresent(lineNumber: number): boolean;
isPresent(position: Position): boolean;
}

class MarkerLineFeature implements LineFeature {
Expand All @@ -191,14 +194,16 @@ class MarkerLineFeature implements LineFeature {
changedUris.some((u) => u.toString() === model.uri.toString())
),
() => /** @description this.markerService.onMarkerChanged */({
isPresent: (lineNumber) => {
isPresent: (position) => {
const hasMarker = this.markerService
.read({ resource: model.uri })
.some(
(m) =>
m.severity === this.severity &&
m.startLineNumber <= lineNumber &&
lineNumber <= m.endLineNumber
m.startLineNumber <= position.lineNumber &&
position.lineNumber <= m.endLineNumber &&
m.startColumn <= position.column &&
position.column <= m.endColumn
);
return hasMarker;
},
Expand All @@ -222,12 +227,12 @@ class FoldedAreaLineFeature implements LineFeature {
foldingController.getFoldingModel() ?? Promise.resolve(undefined)
);
return foldingModel.map<LineFeatureState>((v) => ({
isPresent: (lineNumber) => {
const regionAtLine = v.value?.getRegionAtLine(lineNumber);
isPresent: (position) => {
const regionAtLine = v.value?.getRegionAtLine(position.lineNumber);
const hasFolding = !regionAtLine
? false
: regionAtLine.isCollapsed &&
regionAtLine.startLineNumber === lineNumber;
regionAtLine.startLineNumber === position.lineNumber;
return hasFolding;
},
}));
Expand All @@ -243,10 +248,10 @@ class BreakpointLineFeature implements LineFeature {
return observableFromEvent<LineFeatureState>(
this.debugService.getModel().onDidChangeBreakpoints,
() => /** @description debugService.getModel().onDidChangeBreakpoints */({
isPresent: (lineNumber) => {
isPresent: (position) => {
const breakpoints = this.debugService
.getModel()
.getBreakpoints({ uri: model.uri, lineNumber });
.getBreakpoints({ uri: model.uri, lineNumber: position.lineNumber });
const hasBreakpoints = breakpoints.length > 0;
return hasBreakpoints;
},
Expand Down Expand Up @@ -281,8 +286,8 @@ class InlineCompletionLineFeature implements LineFeature {
return derived<LineFeatureState>('ghostText', reader => {
const ghostText = activeGhostText.read(reader)?.read(reader);
return {
isPresent(lineNumber) {
return ghostText?.lineNumber === lineNumber;
isPresent(position) {
return ghostText?.lineNumber === position.lineNumber;
}
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).regis
'default': 70,
tags: ['accessibility']
},
'audioCues.debouncePositionChanges': {
'description': localize('audioCues.debouncePositionChanges', "Whether or not position changes should be debounced"),
'type': 'boolean',
'default': false,
tags: ['accessibility']
},
'audioCues.lineHasBreakpoint': {
'description': localize('audioCues.lineHasBreakpoint', "Plays a sound when the active line has a breakpoint."),
...audioCueFeatureBase
Expand Down