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

Terser leading/trailing syntax in scm #2113

Merged
merged 5 commits into from
Dec 11, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Attempt at tweaking related range code
pokey committed Dec 11, 2023
commit f5dc4281f295a47961db47e6f867723ee939d6e7
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
Position,
Range,
SimpleScopeType,
TextEditor,
} from "@cursorless/common";
@@ -67,20 +65,26 @@ export class TreeSitterScopeHandler extends BaseTreeSitterScopeHandler {
true,
);

const prefixRange = createRangeWithPosition(
getRelatedRange(match, scopeTypeType, "prefix", true),
contentRange.start,
);
const prefixRange = getRelatedRange(
match,
scopeTypeType,
"prefix",
true,
)?.with(undefined, contentRange.start);

const leadingDelimiterRange = createRangeWithPosition(
getRelatedRange(match, scopeTypeType, "leading", true),
prefixRange?.start ?? contentRange.start,
);
const leadingDelimiterRange = getRelatedRange(
match,
scopeTypeType,
"leading",
true,
)?.with(undefined, prefixRange?.start ?? contentRange.start);

const trailingDelimiterRange = createRangeWithPosition(
getRelatedRange(match, scopeTypeType, "trailing", true),
contentRange.end,
);
const trailingDelimiterRange = getRelatedRange(
match,
scopeTypeType,
"trailing",
true,
)?.with(contentRange.start);

return {
editor,
@@ -103,7 +107,3 @@ export class TreeSitterScopeHandler extends BaseTreeSitterScopeHandler {
};
}
}

function createRangeWithPosition(range: Range | undefined, position: Position) {
return range != null ? range.union(position.toEmptyRange()) : undefined;
}