negotiation.ts ×3

Frontier kind: Code frontier

unlabeled · c_72ab322aa7a7

79 tests · 3867 LOC · 22 files · introduces 0 tests · 38 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
3 ranges38 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
490 ranges3867 lines · 22 files · Browse complete extent
All tests (intent)
79 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 38 introduced LOC across 3 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/common/state/protocol/version/negotiation.ts 38 introduced LOC · 3 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- negotiation.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { compareProtocolVersions } from './registry.js';
7 >
8 > /**
9 > * Parses a `MAJOR.MINOR.PATCH` SemVer string. Returns `undefined` if the
10 > * string is not well-formed. Pre-release / build metadata are not allowed.
11 > */
12 function tryParseSemver(version: string): readonly [number, number, number] | undefined {
13 const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
17 return [Number(match[1]), Number(match[2]), Number(match[3])] as const;
18 }
20 > /**
21 > * Returns whether `offered` is semver-compatible with the server's
22 > * `current` version, using caret semantics:
23 > *
24 > * - majors must match
25 > * - when `major === 0`, minors must also match (because in 0.x semver,
26 > * every minor bump is breaking)
27 > * - the offered version MUST NOT be greater than `current` — a server that
28 > * only knows `0.1.0` cannot pretend to speak `0.1.5`
29 > *
30 > * Invalid version strings return `false`.
31 > */
32 > export function isCompatibleProtocolVersion(offered: string, current: string): boolean {
33 const a = tryParseSemver(offered);
34 const b = tryParseSemver(current);
44 return compareProtocolVersions(offered, current) <= 0;
45 }
47 > /**
48 > * Picks the best version from the client's offered list that this server
49 > * (speaking `current`) can faithfully implement. "Best" means the most
50 > * specific compatible version — i.e. the highest one that is still
51 > * compatible with `current`.
52 > *
53 > * `offered` is expected to be the client's `InitializeParams.protocolVersions`
54 > * (client-preference-ordered, but order is ignored here since we deterministically
55 > * pick the highest compatible entry). Returns `undefined` when no offered
56 > * version is compatible.
57 > */
58 > export function negotiateProtocolVersion(offered: readonly string[], current: string): string | undefined {
59 let best: string | undefined;
60 for (const v of offered) {