Commit d7e9876
Fix no-service-found warning to check for service existence and exclude library namespaces (#8974)
The `no-service-found` warning incorrectly checked for empty routes
instead of checking whether a `@service` decorator exists, and warned on
all namespaces including library namespaces.
## Changes
- **Modified `reportIfNoRoutes` logic**: Now checks
`listServices(program).length === 0` instead of `routes.length === 0` to
determine if any service exists
- **Use `getLocationContext` to filter library code**: Uses
`getLocationContext(program, namespace).type === "project"` to only warn
on user project namespaces, automatically excluding library namespaces
based on source file location
- **Skip global namespace**: Added check to skip the global namespace
(with empty name "")
## Example
Before this change, the following would incorrectly warn on both
namespaces:
```typespec
namespace MyApp {
@get @route("/app") op appOp(): void;
}
namespace TypeSpec.Library {
@get @route("/lib") op libOp(): void;
}
```
After this change, only `MyApp` receives the warning since
`TypeSpec.Library` is from a library package (determined by source file
location, not namespace naming).
> [!WARNING]
>
>
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
>
<__filter_complete__></__filter_complete__></details><issue_title>no-service-found
warning should actually check if there is any service not just
operations</issue_title>
><issue_description>https://azure.github.io/typespec-azure/playground/?e=%40azure-tools%2Ftypespec-autorest&c=aW1wb3J0ICJAYXp1cmUtdG9vbHMvdHlwZXNwZWMtxhVjb3JlIjsKCkBzZXJ2aWNlKCN7IHRpdGxlOiAiQcQiIEFJIiB9KQpuYW1lc3BhY2UgxRcuQUkuUHJvamVjdHMgewoKfQo%3D&options=%7B%7D&vs=%7B%7D
>
>
> ```tsp
> import "@azure-tools/typespec-azure-core";
>
> @service
> namespace Test;
> ```
>
>
> Additionally it would be good that the error is not flagged on all
namespaces, maybe only on user namespaces</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
><comments>
></comments>
>
- Fixes #8973
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>no-service-found warning should actually check if there
is any service not just operations</issue_title>
>
<issue_description>https://azure.github.io/typespec-azure/playground/?e=%40azure-tools%2Ftypespec-autorest&c=aW1wb3J0ICJAYXp1cmUtdG9vbHMvdHlwZXNwZWMtxhVjb3JlIjsKCkBzZXJ2aWNlKCN7IHRpdGxlOiAiQcQiIEFJIiB9KQpuYW1lc3BhY2UgxRcuQUkuUHJvamVjdHMgewoKfQo%3D&options=%7B%7D&vs=%7B%7D
>
>
> ```tsp
> import "@azure-tools/typespec-azure-core";
>
> @service
> namespace Test;
> ```
>
>
> Additionally it would be good that the error is not flagged on all
namespaces, maybe only on user namespaces</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
- Fixes #8973
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: timotheeguerin <[email protected]>
Co-authored-by: Timothee Guerin <[email protected]>1 parent e3c8704 commit d7e9876
File tree
2 files changed
+18
-2
lines changed- .chronus/changes
- packages/http/src
2 files changed
+18
-2
lines changedLines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
110 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
111 | 114 | | |
112 | 115 | | |
113 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
114 | 123 | | |
115 | 124 | | |
116 | 125 | | |
| |||
0 commit comments