mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-11 10:35:57 +03:00
Port getDefinition.md to use projects.
Fix recontextualization of project queries when using relativeTo
This commit is contained in:
parent
9ea0650fc8
commit
bbd02a9129
@ -41,11 +41,11 @@ relocateToNameRoot perspective query rootBranch = do
|
||||
-- Since the project root is lower down we need to strip the part of the prefix
|
||||
-- which is now redundant.
|
||||
pure . Right $ (projectRoot, query <&> \n -> fromMaybe n $ Path.unprefixName (Path.Absolute remainder) n)
|
||||
-- The namesRoot is _inside_ of the project containing the query
|
||||
-- The namesRoot is _inside (or equal to)_ the project containing the query
|
||||
(_sharedPrefix, remainder, Path.Empty) -> do
|
||||
-- Since the project is higher up, we need to prefix the query
|
||||
-- with the remainder of the path
|
||||
pure $ Right (projectRoot, query <&> Path.prefixNameIfRel (Path.AbsolutePath' $ Path.Absolute remainder))
|
||||
pure $ Right (projectRoot, query <&> Path.prefixNameIfRel (Path.RelativePath' $ Path.Relative remainder))
|
||||
-- The namesRoot and project root are disjoint, this shouldn't ever happen.
|
||||
(_, _, _) -> pure $ Left (DisjointProjectAndPerspective perspective projectRoot)
|
||||
|
||||
|
@ -1,54 +1,50 @@
|
||||
# Get Definitions Test
|
||||
|
||||
```ucm:hide
|
||||
scratch/main nested> builtins.mergeio
|
||||
scratch/main> builtins.mergeio lib.builtins
|
||||
```
|
||||
|
||||
```unison:hide
|
||||
{{ Documentation }}
|
||||
names.x = 42
|
||||
nested.names.x.doc = {{ Documentation }}
|
||||
nested.names.x = 42
|
||||
```
|
||||
|
||||
```ucm:hide
|
||||
scratch/main nested> add
|
||||
scratch/main> add
|
||||
```
|
||||
|
||||
```api
|
||||
-- Should NOT find names by suffix
|
||||
GET /api/non-project-code/getDefinition?names=x
|
||||
GET /api/projects/scratch/branches/main/getDefinition?names=x
|
||||
|
||||
-- Term names should strip relativeTo prefix.
|
||||
GET /api/non-project-code/getDefinition?names=names.x&relativeTo=nested
|
||||
GET /api/projects/scratch/branches/main/getDefinition?names=names.x&relativeTo=nested
|
||||
|
||||
-- Should find definitions by hash, names should be relative
|
||||
GET /api/non-project-code/getDefinition?names=%23qkhkl0n238&relativeTo=nested
|
||||
```
|
||||
|
||||
```ucm:hide
|
||||
scratch/main doctest> builtins.mergeio
|
||||
GET /api/projects/scratch/branches/main/getDefinition?names=%23qkhkl0n238&relativeTo=nested
|
||||
```
|
||||
|
||||
```unison:hide
|
||||
thing.doc = {{ The correct docs for the thing }}
|
||||
thing = "A thing"
|
||||
thingalias.doc = {{ Docs for the alias, should not be displayed }}
|
||||
thingalias = "A thing"
|
||||
otherstuff.thing.doc = {{ A doc for a different term with the same name, should not be displayed }}
|
||||
otherstuff.thing = "A different thing"
|
||||
doctest.thing.doc = {{ The correct docs for the thing }}
|
||||
doctest.thing = "A thing"
|
||||
doctest.thingalias.doc = {{ Docs for the alias, should not be displayed }}
|
||||
doctest.thingalias = "A thing"
|
||||
doctest.otherstuff.thing.doc = {{ A doc for a different term with the same name, should not be displayed }}
|
||||
doctest.otherstuff.thing = "A different thing"
|
||||
```
|
||||
|
||||
```ucm:hide
|
||||
scratch/main doctest> add
|
||||
scratch/main> add
|
||||
```
|
||||
|
||||
Only docs for the term we request should be returned, even if there are other term docs with the same suffix.
|
||||
|
||||
```api
|
||||
GET /api/non-project-code/getDefinition?names=thing&relativeTo=doctest
|
||||
GET /api/projects/scratch/branches/main/getDefinition?names=thing&relativeTo=doctest
|
||||
```
|
||||
|
||||
If we request a doc, the api should return the source, but also the rendered doc should appear in the 'termDocs' list.
|
||||
|
||||
```api
|
||||
GET /api/non-project-code/getDefinition?names=thing.doc&relativeTo=doctest
|
||||
GET /api/projects/scratch/branches/main/getDefinition?names=thing.doc&relativeTo=doctest
|
||||
```
|
||||
|
@ -1,13 +1,13 @@
|
||||
# Get Definitions Test
|
||||
|
||||
```unison
|
||||
{{ Documentation }}
|
||||
names.x = 42
|
||||
nested.names.x.doc = {{ Documentation }}
|
||||
nested.names.x = 42
|
||||
```
|
||||
|
||||
```api
|
||||
-- Should NOT find names by suffix
|
||||
GET /api/non-project-code/getDefinition?names=x
|
||||
GET /api/projects/scratch/branches/main/getDefinition?names=x
|
||||
{
|
||||
"missingDefinitions": [
|
||||
"x"
|
||||
@ -16,7 +16,7 @@ GET /api/non-project-code/getDefinition?names=x
|
||||
"typeDefinitions": {}
|
||||
}
|
||||
-- Term names should strip relativeTo prefix.
|
||||
GET /api/non-project-code/getDefinition?names=names.x&relativeTo=nested
|
||||
GET /api/projects/scratch/branches/main/getDefinition?names=names.x&relativeTo=nested
|
||||
{
|
||||
"missingDefinitions": [],
|
||||
"termDefinitions": {
|
||||
@ -104,14 +104,14 @@ GET /api/non-project-code/getDefinition?names=names.x&relativeTo=nested
|
||||
]
|
||||
],
|
||||
"termNames": [
|
||||
"names.x"
|
||||
"nested.names.x"
|
||||
]
|
||||
}
|
||||
},
|
||||
"typeDefinitions": {}
|
||||
}
|
||||
-- Should find definitions by hash, names should be relative
|
||||
GET /api/non-project-code/getDefinition?names=%23qkhkl0n238&relativeTo=nested
|
||||
GET /api/projects/scratch/branches/main/getDefinition?names=%23qkhkl0n238&relativeTo=nested
|
||||
{
|
||||
"missingDefinitions": [],
|
||||
"termDefinitions": {
|
||||
@ -199,30 +199,30 @@ GET /api/non-project-code/getDefinition?names=%23qkhkl0n238&relativeTo=nested
|
||||
]
|
||||
],
|
||||
"termNames": [
|
||||
"names.x"
|
||||
"nested.names.x"
|
||||
]
|
||||
}
|
||||
},
|
||||
"typeDefinitions": {}
|
||||
}
|
||||
``````unison
|
||||
thing.doc = {{ The correct docs for the thing }}
|
||||
thing = "A thing"
|
||||
thingalias.doc = {{ Docs for the alias, should not be displayed }}
|
||||
thingalias = "A thing"
|
||||
otherstuff.thing.doc = {{ A doc for a different term with the same name, should not be displayed }}
|
||||
otherstuff.thing = "A different thing"
|
||||
doctest.thing.doc = {{ The correct docs for the thing }}
|
||||
doctest.thing = "A thing"
|
||||
doctest.thingalias.doc = {{ Docs for the alias, should not be displayed }}
|
||||
doctest.thingalias = "A thing"
|
||||
doctest.otherstuff.thing.doc = {{ A doc for a different term with the same name, should not be displayed }}
|
||||
doctest.otherstuff.thing = "A different thing"
|
||||
```
|
||||
|
||||
Only docs for the term we request should be returned, even if there are other term docs with the same suffix.
|
||||
|
||||
```api
|
||||
GET /api/non-project-code/getDefinition?names=thing&relativeTo=doctest
|
||||
GET /api/projects/scratch/branches/main/getDefinition?names=thing&relativeTo=doctest
|
||||
{
|
||||
"missingDefinitions": [],
|
||||
"termDefinitions": {
|
||||
"#jksc1s5kud95ro5ivngossullt2oavsd41s3u48bch67jf3gknru5j6hmjslonkd5sdqs8mr8k4rrnef8fodngbg4sm7u6au564ekjg": {
|
||||
"bestTermName": "thing",
|
||||
"bestTermName": "doctest.thing",
|
||||
"defnTermTag": "Plain",
|
||||
"signature": [
|
||||
{
|
||||
@ -237,10 +237,10 @@ GET /api/non-project-code/getDefinition?names=thing&relativeTo=doctest
|
||||
"contents": [
|
||||
{
|
||||
"annotation": {
|
||||
"contents": "thing",
|
||||
"contents": "doctest.thing",
|
||||
"tag": "HashQualifier"
|
||||
},
|
||||
"segment": "thing"
|
||||
"segment": "doctest.thing"
|
||||
},
|
||||
{
|
||||
"annotation": {
|
||||
@ -265,10 +265,10 @@ GET /api/non-project-code/getDefinition?names=thing&relativeTo=doctest
|
||||
},
|
||||
{
|
||||
"annotation": {
|
||||
"contents": "thing",
|
||||
"contents": "doctest.thing",
|
||||
"tag": "HashQualifier"
|
||||
},
|
||||
"segment": "thing"
|
||||
"segment": "doctest.thing"
|
||||
},
|
||||
{
|
||||
"annotation": {
|
||||
@ -291,7 +291,7 @@ GET /api/non-project-code/getDefinition?names=thing&relativeTo=doctest
|
||||
},
|
||||
"termDocs": [
|
||||
[
|
||||
"thing.doc",
|
||||
"doctest.thing.doc",
|
||||
"#t9qfdoiuskj4n9go8cftj1r83s43s3o7sppafm5vr0bq5feieb7ap0cie5ed2qsf9g3ig448vffhnajinq81pnnkila1jp2epa7f26o",
|
||||
{
|
||||
"contents": [
|
||||
@ -325,8 +325,8 @@ GET /api/non-project-code/getDefinition?names=thing&relativeTo=doctest
|
||||
]
|
||||
],
|
||||
"termNames": [
|
||||
"thing",
|
||||
"thingalias"
|
||||
"doctest.thing",
|
||||
"doctest.thingalias"
|
||||
]
|
||||
}
|
||||
},
|
||||
@ -335,12 +335,12 @@ GET /api/non-project-code/getDefinition?names=thing&relativeTo=doctest
|
||||
```If we request a doc, the api should return the source, but also the rendered doc should appear in the 'termDocs' list.
|
||||
|
||||
```api
|
||||
GET /api/non-project-code/getDefinition?names=thing.doc&relativeTo=doctest
|
||||
GET /api/projects/scratch/branches/main/getDefinition?names=thing.doc&relativeTo=doctest
|
||||
{
|
||||
"missingDefinitions": [],
|
||||
"termDefinitions": {
|
||||
"#t9qfdoiuskj4n9go8cftj1r83s43s3o7sppafm5vr0bq5feieb7ap0cie5ed2qsf9g3ig448vffhnajinq81pnnkila1jp2epa7f26o": {
|
||||
"bestTermName": "thing.doc",
|
||||
"bestTermName": "doctest.thing.doc",
|
||||
"defnTermTag": "Doc",
|
||||
"signature": [
|
||||
{
|
||||
@ -355,10 +355,10 @@ GET /api/non-project-code/getDefinition?names=thing.doc&relativeTo=doctest
|
||||
"contents": [
|
||||
{
|
||||
"annotation": {
|
||||
"contents": "thing.doc",
|
||||
"contents": "doctest.thing.doc",
|
||||
"tag": "HashQualifier"
|
||||
},
|
||||
"segment": "thing.doc"
|
||||
"segment": "doctest.thing.doc"
|
||||
},
|
||||
{
|
||||
"annotation": {
|
||||
@ -383,10 +383,10 @@ GET /api/non-project-code/getDefinition?names=thing.doc&relativeTo=doctest
|
||||
},
|
||||
{
|
||||
"annotation": {
|
||||
"contents": "thing.doc",
|
||||
"contents": "doctest.thing.doc",
|
||||
"tag": "HashQualifier"
|
||||
},
|
||||
"segment": "thing.doc"
|
||||
"segment": "doctest.thing.doc"
|
||||
},
|
||||
{
|
||||
"annotation": {
|
||||
@ -467,7 +467,7 @@ GET /api/non-project-code/getDefinition?names=thing.doc&relativeTo=doctest
|
||||
},
|
||||
"termDocs": [
|
||||
[
|
||||
"thing.doc",
|
||||
"doctest.thing.doc",
|
||||
"#t9qfdoiuskj4n9go8cftj1r83s43s3o7sppafm5vr0bq5feieb7ap0cie5ed2qsf9g3ig448vffhnajinq81pnnkila1jp2epa7f26o",
|
||||
{
|
||||
"contents": [
|
||||
@ -501,7 +501,7 @@ GET /api/non-project-code/getDefinition?names=thing.doc&relativeTo=doctest
|
||||
]
|
||||
],
|
||||
"termNames": [
|
||||
"thing.doc"
|
||||
"doctest.thing.doc"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user