@hia-doc/dotnetdoc-runner 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/package.json +5 -5
- package/src/index.mjs +4 -31
- package/src/source-locations.mjs +163 -0
package/README.md
CHANGED
|
@@ -68,3 +68,28 @@ resolution、confidence、provenance 分开输出。relation 仍是 metadata-onl
|
|
|
68
68
|
"title": "Web Markup Comments"
|
|
69
69
|
}
|
|
70
70
|
```
|
|
71
|
+
|
|
72
|
+
## Code source locations
|
|
73
|
+
|
|
74
|
+
Compiler XML paths are documentation origins. They stay in extraction `member.source`
|
|
75
|
+
and HIA `metadata.dotnetdoc.documentationSource`; they are not exposed as code definitions.
|
|
76
|
+
For real C# locations, use a configured `dotnet-project` solution/project input or set
|
|
77
|
+
`projectPath` on an XML input. The runner reuses its Roslyn extractor and requires a
|
|
78
|
+
unique assembly and complete documentation-comment ID match. It does not add duplicate
|
|
79
|
+
C# documentation pages and works with `writeSourceRelationArtifact: false`.
|
|
80
|
+
|
|
81
|
+
Unresolved or ambiguous members have no code locator. Conflicting declarations, missing
|
|
82
|
+
references, unavailable .NET tooling and sources outside the workspace are never repaired
|
|
83
|
+
by choosing an arbitrary filename. Extraction reads configured source only; it does not
|
|
84
|
+
execute the target build, download source, parse Windows/Portable PDBs or grant publication
|
|
85
|
+
permission. Existing source preview settings still require explicit publication consent.
|
|
86
|
+
|
|
87
|
+
中文:XML是文档出处;代码定位来自已配置项目中的唯一真实Roslyn声明。缺失/歧义保持未定位,
|
|
88
|
+
不会回退XML或按名称猜文件。需要现有.NET 8 SDK/helper;本轮不实现PDB读取,尤其不能把传统
|
|
89
|
+
Windows PDB当作Portable PDB。范围与语言随真实声明输出,所有XML注释/本地化字段保持。
|
|
90
|
+
|
|
91
|
+
### Coverage diagnostics (0.1.12)
|
|
92
|
+
|
|
93
|
+
Read `document.metadata.sourceLocationResolution` for coverage counts and reference-warning codes, and each `symbol.diagnostics` for `data.symbolId`, `memberName`, `reason` (`missing`/`ambiguous`) and detail. Proven partial types prefer a non-generated declaration, then stable path/start position; the selected rule and candidate count appear in `symbol.metadata.dotnetdoc.sourceLocationResolution`. Duplicate inputs are not silently collapsed. Re-extract artifacts after upgrading; source publication still requires the existing explicit authorization.
|
|
94
|
+
|
|
95
|
+
中文:计数在metadata层;未定位成员逐项带诊断,合法partial记录主声明选择。升级后重新抽取,不改变公开授权。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hia-doc/dotnetdoc-runner",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "Standalone .NET XML documentation runner and CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"LICENSE"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@hia-doc/dotnet-source-extractor": "0.1.
|
|
40
|
-
"@hia-doc/dotnet-xml-doc-extractor": "0.1.
|
|
41
|
-
"@hia-doc/dotnetdoc-adapter": "0.1.
|
|
42
|
-
"@hia-doc/dotnetdoc-spec": "0.1.
|
|
39
|
+
"@hia-doc/dotnet-source-extractor": "0.1.12",
|
|
40
|
+
"@hia-doc/dotnet-xml-doc-extractor": "0.1.12",
|
|
41
|
+
"@hia-doc/dotnetdoc-adapter": "0.1.12",
|
|
42
|
+
"@hia-doc/dotnetdoc-spec": "0.1.12"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/src/index.mjs
CHANGED
|
@@ -27,12 +27,13 @@ export {
|
|
|
27
27
|
DOTNETDOC_CONFIG_SCHEMA_VERSION
|
|
28
28
|
} from "./schema.mjs";
|
|
29
29
|
import { DOTNETDOC_CONFIG_SCHEMA_ID, DOTNETDOC_CONFIG_SCHEMA_VERSION } from "./schema.mjs";
|
|
30
|
+
import { enrichXmlSourceLocations } from "./source-locations.mjs";
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* @lang zh-CN DotNetDoc runner/producer 的公开包版本;它与各个 `0.1.0-draft` artifact contract version 分离。
|
|
33
34
|
* @lang en Public package version of the DotNetDoc runner/producer, kept separate from every `0.1.0-draft` artifact contract version.
|
|
34
35
|
*/
|
|
35
|
-
export const DOTNETDOC_RUNNER_VERSION = "0.1.
|
|
36
|
+
export const DOTNETDOC_RUNNER_VERSION = "0.1.12";
|
|
36
37
|
export const DOTNETDOC_INPUT_KINDS = Object.freeze(["dotnet-xml-doc", "dotnet-csharp-source", "dotnet-aspnet-surface", "dotnet-markup-comments", "dotnet-project"]);
|
|
37
38
|
export const DOTNETDOC_OUTPUT_KINDS = Object.freeze(["dotnetdoc-extraction", "hia-document", "dotnetdoc-source-relation", "dotnetdoc-aspnet-endpoint-extraction", "dotnetdoc-markup-comment-extraction", "dotnetdoc-project-discovery"]);
|
|
38
39
|
export const DOTNETDOC_BUILD_WARNING_CLASSIFICATION_CONTRACT = "dotnetdoc-build-warning-classification";
|
|
@@ -100,7 +101,7 @@ export async function runDotnetDoc(request, context = {}) {
|
|
|
100
101
|
|
|
101
102
|
// <lang><zh-CN>精确声明投影独立于是否输出relation文件;单独消费XML的HIA产物也保留签名。</zh-CN><en>Exact declaration projection is independent of relation-file emission, retaining signatures in XML-derived HIA artifacts consumed alone.</en></lang>
|
|
102
103
|
const sourceRelation = buildSourceRelationArtifact(extractionRecords, normalized);
|
|
103
|
-
await
|
|
104
|
+
diagnostics.push(...await enrichXmlSourceLocations(extractionRecords, normalized));
|
|
104
105
|
if (sourceRelation && normalized.options.writeSourceRelationArtifact) {
|
|
105
106
|
const relationPath = "dotnetdoc.source-relation.json";
|
|
106
107
|
await writeJson(path.join(normalized.outputDirectory, relationPath), sourceRelation);
|
|
@@ -138,35 +139,7 @@ export async function runDotnetDoc(request, context = {}) {
|
|
|
138
139
|
return result;
|
|
139
140
|
}
|
|
140
141
|
|
|
141
|
-
|
|
142
|
-
* @lang zh-CN 仅将唯一、文档ID完全一致的Roslyn声明投影进XML派生HIA;不改变XML原始抽取或注释字段。
|
|
143
|
-
* @lang en Projects only unique Roslyn declarations with identical documentation IDs into XML-derived HIA, without altering raw XML extraction or comment fields.
|
|
144
|
-
* @param {object[]} records <lang><zh-CN>当前请求内已抽取记录,不重新发现源码。</zh-CN><en>Extraction records from this request; no source rediscovery.</en></lang>
|
|
145
|
-
* @param {object|null} relation <lang><zh-CN>当前请求的关系事实;缺失/模糊/回退匹配均不升级。</zh-CN><en>Relation facts for this request; absent, ambiguous and fallback matches never upgrade signatures.</en></lang>
|
|
146
|
-
* @param {object} request <lang><zh-CN>已规范化输出根,仍只写既定HIA路径。</zh-CN><en>Normalized output root; writes remain at existing HIA paths.</en></lang>
|
|
147
|
-
* @returns {Promise<void>} <lang><zh-CN>写回获精确签名的HIA文件,保持成员身份和注释内容。</zh-CN><en>Rewrites HIA files with exact signatures, retaining member identity and comment content.</en></lang>
|
|
148
|
-
*/
|
|
149
|
-
async function enrichXmlHiaSignatures(records, relation, request) {
|
|
150
|
-
if (!relation) return;
|
|
151
|
-
for (const record of records) {
|
|
152
|
-
if (record.artifact.contract !== DOTNETDOC_XML_DOC_EXTRACTION_CONTRACT) continue;
|
|
153
|
-
// <lang><zh-CN>同名多声明包括跨工程重复身份;不能按数组先后任意挑一个。</zh-CN><en>Multiple declarations include cross-project duplicate identities; array order must never choose an arbitrary winner.</en></lang>
|
|
154
|
-
let changed = false;
|
|
155
|
-
const members = record.artifact.members.map((member) => {
|
|
156
|
-
const matches = relation.relations.filter((item) => item.hiaSymbol.artifactPath === record.hiaPath && item.hiaSymbol.id === member.id);
|
|
157
|
-
if (matches.length !== 1) return member;
|
|
158
|
-
const exact = matches[0];
|
|
159
|
-
const semantic = exact.declaration?.semantic;
|
|
160
|
-
if (exact.match?.exactDocumentationId !== true || semantic?.documentationCommentId !== member.memberName || typeof semantic.signature !== "string" || !semantic.signature.trim()) return member;
|
|
161
|
-
changed = true;
|
|
162
|
-
return { ...member, semantic: { ...member.semantic, ...semantic } };
|
|
163
|
-
});
|
|
164
|
-
if (!changed) continue;
|
|
165
|
-
// <lang><zh-CN>适配器继续负责显式签名优先级和i18n投影,避免建立第二套转换逻辑。</zh-CN><en>The adapter retains responsibility for explicit-signature precedence and i18n projection, avoiding a second conversion implementation.</en></lang>
|
|
166
|
-
record.hiaDocument = dotnetXmlDocsToHiaDocument({ ...record.artifact, members }, { id: record.input.hiaDocumentId, title: record.input.title });
|
|
167
|
-
await writeJson(path.join(request.outputDirectory, record.hiaPath), record.hiaDocument);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
142
|
+
|
|
170
143
|
|
|
171
144
|
/**
|
|
172
145
|
* 将 .NET build / MSBuild 文本诊断分类为 manual、designer 或 generated 边界。
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* @lang zh-CN 将配置项目中的唯一Roslyn声明投影为XML文档成员的代码定位;不猜路径、不执行业务构建。
|
|
4
|
+
* @lang en Projects unique Roslyn declarations from configured projects into XML member code locators without path guessing or target builds.
|
|
5
|
+
*/
|
|
6
|
+
import { realpath, writeFile } from 'node:fs/promises';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { extractDotnetProjectDiscovery, extractDotnetSourceFiles } from '@hia-doc/dotnet-source-extractor';
|
|
9
|
+
import { dotnetXmlDocsToHiaDocument } from '@hia-doc/dotnetdoc-adapter';
|
|
10
|
+
import { DOTNETDOC_XML_DOC_EXTRACTION_CONTRACT, DOTNETDOC_CSHARP_SOURCE_EXTRACTION_CONTRACT, DOTNETDOC_PROJECT_DISCOVERY_CONTRACT } from '@hia-doc/dotnetdoc-spec';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @lang zh-CN 按完整成员ID选声明;同次抽取的真实partial类型选主声明,重复注册/跨抽取冲突仍拒绝。
|
|
14
|
+
* @lang en Selects declarations by complete member ID; genuine partial types from one extraction select a primary declaration, while duplicates and cross-extraction conflicts remain refused.
|
|
15
|
+
* @param {object} member <lang><zh-CN>XML成员身份。</zh-CN><en>XML member identity.</en></lang>
|
|
16
|
+
* @param {object[]} candidates <lang><zh-CN>声明及其程序集身份。</zh-CN><en>Declarations with assembly identities.</en></lang>
|
|
17
|
+
* @param {string|null} assembly <lang><zh-CN>XML声明的程序集。</zh-CN><en>Assembly declared by the XML input.</en></lang>
|
|
18
|
+
* @returns {{declaration?:object,status:string,candidateCount:number,selectionRule?:string}} <lang><zh-CN>精确/partial主声明或missing/ambiguous,含候选数与选择规则;不按简称或参数数量回退。</zh-CN><en>Exact/partial primary declaration or missing/ambiguous, with candidate count and selection rule; no short-name or arity fallback.</en></lang>
|
|
19
|
+
*/
|
|
20
|
+
export function selectExactDeclaration(member, candidates, assembly) {
|
|
21
|
+
// <lang><zh-CN>完整ID及签名类型先验证;相同位置重复注册不自动合并为同一输入事实。</zh-CN><en>Validate complete IDs and signature types first; duplicate registrations at the same location do not automatically become one input fact.</en></lang>
|
|
22
|
+
const unique = [];
|
|
23
|
+
for (const candidate of candidates) {
|
|
24
|
+
if (candidate.member.semantic?.documentationCommentId !== member.memberName || candidate.member.semantic?.hasUnresolvedSignatureTypes === true) continue;
|
|
25
|
+
if (assembly && candidate.assembly && candidate.assembly !== 'DotNetDoc.SourceExtraction' && candidate.assembly !== assembly) continue;
|
|
26
|
+
unique.push(candidate);
|
|
27
|
+
}
|
|
28
|
+
if(unique.length===1) return {status:'resolved',declaration:unique[0].member,candidateCount:1,selectionRule:'exact-documentation-id'};
|
|
29
|
+
// <lang><zh-CN>partial必须来自同一编译事实、同一程序集且位置各异;普通重复不能靠排序变成有效声明。</zh-CN><en>Partial declarations must share a compilation and assembly with distinct locations; ordering cannot legitimize ordinary duplicates.</en></lang>
|
|
30
|
+
const first=unique[0];
|
|
31
|
+
const locations=new Set(unique.map(candidate=>`${candidate.member.source?.path}:${candidate.member.source?.range?.start?.line}:${candidate.member.source?.range?.start?.column}`));
|
|
32
|
+
if(unique.length>1 && first.origin && locations.size===unique.length && unique.every(candidate=>candidate.origin===first.origin && candidate.assembly===first.assembly && candidate.member.kind==='dotnet-type' && candidate.member.semantic?.declaration?.isPartialType===true && candidate.member.semantic.declaration.declarationCount===unique.length)){
|
|
33
|
+
const ranked=[...unique].sort(compareDeclarations);
|
|
34
|
+
return {status:'resolved',declaration:ranked[0].member,candidateCount:unique.length,selectionRule:'non-generated-path-line'};
|
|
35
|
+
}
|
|
36
|
+
return {status:unique.length===0?'missing':'ambiguous',candidateCount:unique.length};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @lang zh-CN 排序仅用于已证明的同一partial语义符号,不使用宿主locale。 @lang en Orders only proven parts of the same semantic symbol, independently of host locale. */
|
|
40
|
+
function compareDeclarations(left,right){
|
|
41
|
+
const a=left.member,b=right.member;
|
|
42
|
+
const generated=Number(a.semantic.declaration.isGenerated)-Number(b.semantic.declaration.isGenerated);
|
|
43
|
+
const aPath=a.source.path.replaceAll('\\','/'),bPath=b.source.path.replaceAll('\\','/');
|
|
44
|
+
return generated || (aPath<bPath?-1:aPath>bPath?1:0) || a.source.range.start.line-b.source.range.start.line || (a.source.range.start.column??1)-(b.source.range.start.column??1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @lang zh-CN 在既有HIA输出路径补全源码/签名;原XML extraction wire及文档字段不修改。
|
|
49
|
+
* @lang en Enriches source/signature at existing HIA output paths without changing raw XML extraction wire data or documentation fields.
|
|
50
|
+
* @param {object[]} records <lang><zh-CN>当前请求抽取记录。</zh-CN><en>Extraction records from this request.</en></lang>
|
|
51
|
+
* @param {object} request <lang><zh-CN>规范化工作区/输出根。</zh-CN><en>Normalized workspace/output roots.</en></lang>
|
|
52
|
+
* @returns {Promise<object[]>} <lang><zh-CN>每个XML输入至多一条未定位警告,无正文或绝对路径。</zh-CN><en>At most one unresolved warning per XML input, without bodies or absolute paths.</en></lang>
|
|
53
|
+
*/
|
|
54
|
+
export async function enrichXmlSourceLocations(records, request) {
|
|
55
|
+
// <lang><zh-CN>只使用已配置发现结果或XML输入显式绑定的projectPath;不扫描整个业务工作区。</zh-CN><en>Use configured discovery results or an XML input's explicit projectPath only, without scanning the target workspace.</en></lang>
|
|
56
|
+
const projects = new Map(records.filter(record => record.artifact.contract === DOTNETDOC_PROJECT_DISCOVERY_CONTRACT).flatMap(record => record.artifact.projects ?? []).map(project => [project.path, project]));
|
|
57
|
+
const explicit = records.filter(record => record.artifact.contract === DOTNETDOC_CSHARP_SOURCE_EXTRACTION_CONTRACT).flatMap(record => candidatesFrom(record.artifact));
|
|
58
|
+
const cache = new Map();
|
|
59
|
+
const diagnostics = [];
|
|
60
|
+
for (const record of records) {
|
|
61
|
+
if (record.artifact.contract !== DOTNETDOC_XML_DOC_EXTRACTION_CONTRACT) continue;
|
|
62
|
+
// <lang><zh-CN>程序集匹配先于源码抽取;同名不同工程不能按文件顺序决定归属。</zh-CN><en>Assembly matching precedes source extraction; input order cannot resolve ownership between projects.</en></lang>
|
|
63
|
+
const assembly = record.artifact.assembly?.name;
|
|
64
|
+
let available = [...projects.values()];
|
|
65
|
+
if (record.input.projectPath) {
|
|
66
|
+
try {
|
|
67
|
+
await assertContainedFile(request.workspaceRoot, record.input.projectPath);
|
|
68
|
+
const discovery = await extractDotnetProjectDiscovery({ workspaceRoot: request.workspaceRoot, paths: [record.input.projectPath] });
|
|
69
|
+
available = discovery.projects;
|
|
70
|
+
} catch { available = []; }
|
|
71
|
+
}
|
|
72
|
+
const matches = assembly ? available.filter(project => (project.assemblyName ?? project.name) === assembly) : [];
|
|
73
|
+
// <lang><zh-CN>每项目串行抽取并缓存一次;失败也是本请求缓存结果,不反复启动helper。</zh-CN><en>Extract each project serially once and cache failures too, preventing repeated helper launches.</en></lang>
|
|
74
|
+
let discovered = [];
|
|
75
|
+
let referenceDiagnosticCodes = [];
|
|
76
|
+
if (matches.length === 1) {
|
|
77
|
+
const project = matches[0];
|
|
78
|
+
const referenceDirectory=path.posix.dirname(record.input.path.replaceAll('\\','/'));
|
|
79
|
+
const cacheKey=`${project.path}\n${referenceDirectory}`;
|
|
80
|
+
if (!cache.has(cacheKey)) cache.set(cacheKey, await readProjectCandidates(project, request.workspaceRoot, referenceDirectory));
|
|
81
|
+
const extracted=cache.get(cacheKey);
|
|
82
|
+
discovered = extracted.candidates;
|
|
83
|
+
referenceDiagnosticCodes=extracted.referenceDiagnosticCodes;
|
|
84
|
+
}
|
|
85
|
+
// <lang><zh-CN>显式输入对其成员ID优先;自动项目发现不重复注册同一显式身份,显式输入之间的重复仍拒绝。</zh-CN><en>Explicit inputs take precedence for their member IDs; automatic discovery never duplicates an explicit identity, while duplicates between explicit inputs remain refused.</en></lang>
|
|
86
|
+
const explicitIds = new Set(explicit.filter(candidate => !assembly || !candidate.assembly || candidate.assembly === assembly || candidate.assembly === 'DotNetDoc.SourceExtraction').map(candidate => candidate.member.semantic?.documentationCommentId));
|
|
87
|
+
const candidates = [...explicit, ...discovered.filter(candidate => !explicitIds.has(candidate.member.semantic?.documentationCommentId))];
|
|
88
|
+
const byId = new Map();
|
|
89
|
+
for (const candidate of candidates) {
|
|
90
|
+
const id = candidate.member.semantic?.documentationCommentId;
|
|
91
|
+
if (!id) continue;
|
|
92
|
+
const bucket = byId.get(id) ?? [];
|
|
93
|
+
bucket.push(candidate);
|
|
94
|
+
byId.set(id, bucket);
|
|
95
|
+
}
|
|
96
|
+
// <lang><zh-CN>统计是有界元数据;每个符号保留XML原文/i18n,只合并验证后的代码声明。
|
|
97
|
+
// </zh-CN><en>Counts are bounded metadata; each symbol retains XML text/i18n and merges only verified code declarations.</en></lang>
|
|
98
|
+
const summary = { strategy: 'assembly-and-documentation-id', resolved: 0, ambiguous: 0, missing: 0, resolvedPartial: 0, referenceDiagnosticCodes };
|
|
99
|
+
const members = [];
|
|
100
|
+
// <lang><zh-CN>逐成员记录与计数在同一循环生成,避免诊断和source事实漂移。</zh-CN><en>Generate per-member records and counts in one loop to keep diagnostics aligned with source facts.</en></lang>
|
|
101
|
+
const resolutions=[];
|
|
102
|
+
for (const member of record.artifact.members) {
|
|
103
|
+
const selected = selectExactDeclaration(member, byId.get(member.memberName) ?? [], assembly);
|
|
104
|
+
if (selected.status !== 'resolved') { summary[selected.status] += 1; members.push(member); resolutions.push({status:selected.status,candidateCount:selected.candidateCount,reason:selected.status,detail:referenceDiagnosticCodes.length?'metadata-reference-or-project-unavailable':'no-unique-exact-declaration'}); continue; }
|
|
105
|
+
const declaration = selected.declaration;
|
|
106
|
+
try {
|
|
107
|
+
await assertContainedFile(request.workspaceRoot, declaration.source.path);
|
|
108
|
+
if (!/\.cs$/iu.test(declaration.source.path) || !validRange(declaration.source.range)) throw new Error('Not a bounded C# declaration');
|
|
109
|
+
summary.resolved += 1;
|
|
110
|
+
if(selected.selectionRule==='non-generated-path-line') summary.resolvedPartial+=1;
|
|
111
|
+
members.push({ ...member, source: declaration.source, semantic: { ...member.semantic, ...declaration.semantic } });
|
|
112
|
+
resolutions.push({status:'resolved',candidateCount:selected.candidateCount,selectionRule:selected.selectionRule});
|
|
113
|
+
} catch { summary.missing += 1; members.push(member); resolutions.push({status:'missing',reason:'missing',detail:'unsafe-or-invalid-declaration-location',candidateCount:selected.candidateCount}); }
|
|
114
|
+
}
|
|
115
|
+
const document = dotnetXmlDocsToHiaDocument({ ...record.artifact, members }, { id: record.input.hiaDocumentId, title: record.input.title });
|
|
116
|
+
document.metadata.sourceLocationResolution = summary;
|
|
117
|
+
for(const [index,symbol] of document.symbols.entries()){
|
|
118
|
+
const resolution=resolutions[index];
|
|
119
|
+
symbol.metadata.dotnetdoc.sourceLocationResolution=resolution;
|
|
120
|
+
if(resolution.status!=='resolved') symbol.diagnostics.push({code:resolution.status==='ambiguous'?'DOTNETDOC_SOURCE_LOCATION_AMBIGUOUS':'DOTNETDOC_SOURCE_LOCATION_MISSING',message:'No unique verified C# location is available for this documentation member.',severity:'warning',data:{symbolId:symbol.id,memberName:symbol.metadata.dotnetdoc.memberName,...resolution}});
|
|
121
|
+
}
|
|
122
|
+
if(summary.missing||summary.ambiguous) document.diagnostics.push({code:'DOTNETDOC_SOURCE_LOCATION_UNRESOLVED',message:'Some documentation members have no unique verified C# location; inspect member diagnostics and metadata.sourceLocationResolution.',severity:'warning',data:summary});
|
|
123
|
+
record.hiaDocument = document;
|
|
124
|
+
await writeFile(path.join(request.outputDirectory, record.hiaPath), `${JSON.stringify(document, null, 2)}\n`, 'utf8');
|
|
125
|
+
if (summary.missing || summary.ambiguous) diagnostics.push({ code: 'DOTNETDOC_SOURCE_LOCATION_UNRESOLVED', message: 'Some XML members have no unique C# declaration. Configure the matching project/source inputs and resolve missing references; XML origins are not exposed as code.', severity: 'warning', source: { path: record.input.path }, metadata: summary });
|
|
126
|
+
}
|
|
127
|
+
return diagnostics;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** @lang zh-CN 从已有抽取结果取身份和定位,不复制方法体。 @lang en Selects identities/locators from existing extraction results without copying method bodies. */
|
|
131
|
+
function candidatesFrom(artifact) {
|
|
132
|
+
return artifact.members.map(member => ({ member, assembly: artifact.assembly?.name ?? member.semantic?.containingAssembly, origin: artifact }));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** @lang zh-CN 受限项目只读抽取;任何路径/工具失败都变为未定位,不泄露底层错误。 @lang en Performs bounded read-only project extraction, mapping path/tool failures to unresolved locations without leaking underlying errors. */
|
|
136
|
+
async function readProjectCandidates(project, root, referenceDirectory) {
|
|
137
|
+
try {
|
|
138
|
+
await assertContainedFile(root, project.path);
|
|
139
|
+
// <lang><zh-CN>显式Compile条目先验证真实路径;SDK默认遍历不跟随symlink,项目根仍须在工作区内。</zh-CN><en>Validate real paths of explicit Compile items first; SDK enumeration does not follow symlinks and its project root must remain inside the workspace.</en></lang>
|
|
140
|
+
for (const item of project.compileItems ?? []) {
|
|
141
|
+
if (typeof item.include !== 'string' || !/\.cs$/iu.test(item.include)) continue;
|
|
142
|
+
const sourcePath = path.posix.normalize(path.posix.join(path.posix.dirname(project.path), item.include.replaceAll('\\', '/')));
|
|
143
|
+
await assertContainedFile(root, sourcePath);
|
|
144
|
+
}
|
|
145
|
+
const artifact=await extractDotnetSourceFiles({ workspaceRoot: root, projectPath: project.path, referenceDirectory });
|
|
146
|
+
return {candidates:candidatesFrom(artifact),referenceDiagnosticCodes:[...new Set((artifact.diagnostics??[]).filter(item=>/^DOTNETDOC_(?:METADATA|FRAMEWORK)_REFERENCE/u.test(item.code)).map(item=>item.code))].sort()};
|
|
147
|
+
} catch { return {candidates:[],referenceDiagnosticCodes:['DOTNETDOC_SOURCE_PROJECT_UNAVAILABLE']}; }
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** @lang zh-CN 双重路径包含检查,不读取越界symlink目标正文。 @lang en Checks lexical and real-path containment without reading bodies behind escaping symlinks. */
|
|
151
|
+
async function assertContainedFile(root, relative) {
|
|
152
|
+
if (typeof relative !== 'string' || /^(?:[/\\]|[a-z][a-z0-9+.-]*:)/iu.test(relative) || relative.replaceAll('\\', '/').split('/').includes('..')) throw new Error('Unsafe source locator');
|
|
153
|
+
const [realRoot, realFile] = await Promise.all([realpath(root), realpath(path.resolve(root, relative))]);
|
|
154
|
+
const inside = path.relative(realRoot, realFile);
|
|
155
|
+
if (path.isAbsolute(inside) || inside === '..' || inside.startsWith(`..${path.sep}`)) throw new Error('Source leaves workspace');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** @lang zh-CN 只接受一基有序物理范围;不从XML默认第一行。 @lang en Accepts one-based ordered physical ranges without defaulting XML to line one. */
|
|
159
|
+
function validRange(range) {
|
|
160
|
+
const start = range?.start;
|
|
161
|
+
const end = range?.end;
|
|
162
|
+
return Number.isSafeInteger(start?.line) && start.line > 0 && Number.isSafeInteger(end?.line) && end.line >= start.line && (start.column === undefined || Number.isSafeInteger(start.column) && start.column > 0) && (end.column === undefined || Number.isSafeInteger(end.column) && end.column > 0) && (end.line !== start.line || end.column === undefined || start.column === undefined || end.column >= start.column);
|
|
163
|
+
}
|